Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT
What is the length of the longest common subsequence of "dbacabb" and its cyclic rotation by one position (the string with its first letter moved to the end)?
- A. 7
- B. 6
- C. 1
- D. 14
Correct answer: B. 6
Rotating by one moves only the first letter, so keeping everything except that letter is a common subsequence: LCS = n − 1 = 6, and 7 would need the strings to be identical. Comparing position by position finds only 1 match, and 14 adds the two lengths.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Using only insertions and deletions (no substitutions), what is the minimum number of operations needed to turn "heat" into "hit"?
- How many permutations of the numbers 1 to 6 have a longest increasing subsequence of length exactly 3?
- How many permutations of 1, 2, 3, 4, 5 have EXACTLY 4 inversions? An inversion is a pair of positions i < j with p[i] > p[j].
- Piles of stones [3, 5, 1, 2, 6] are in a row. Each move merges two ADJACENT piles into one, at a cost equal to their combined number of…
- In how many different ways can the product of 5 matrices A·B·C·D·E be fully parenthesised (grouping by brackets, keeping the order of…
- Two players alternately take a pile from either END of the row [4, 15, 3, 9, 2, 8]; the first player moves first and each takes the whole…