GATE Computer ScienceHardGATE CS (PYQ pattern)

The longest repeating subsequence of a string is the longest subsequence that occurs twice, where the two copies may overlap in positions but the k-th characters of the two copies must come from different positions. What is its length for XYZXYZXY?

  1. A. 5
  2. B. 4
  3. C. 6
  4. D. 7

Correct answer: A. 5

Take the LCS DP of the string with itself, but forbid matching a character with itself (i ≠ j). The result is 5: XYZXY occurs at positions (0,1,2,3,4) and (3,4,5,6,7), and the pairs of positions are all different.

More Algorithms questions

Exams that ask this topic