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)?

  1. A. 7
  2. B. 6
  3. C. 1
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic