Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

What is the length of the longest repeating subsequence of "aabebcdd"? It is a subsequence that appears at least twice, where the two copies use DIFFERENT indices at every position.

  1. A. 0
  2. B. 4
  3. C. 2
  4. D. 3

Correct answer: D. 3

dp over pairs (i, j) with i ≠ j: when s[i] = s[j] and i ≠ j, extend the diagonal. Computing LCS(s, s) allows matching a letter to itself at the same index and gives the full length, which is not allowed.

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

Exams that ask this topic