Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

What is the length of the longest common subsequence of the three strings "ABCBDAB", "BDCABA" and "BCADB"?

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

Correct answer: A. 4

Use a three-dimensional DP: if the three current letters match, add 1 to the diagonal; otherwise take the best of dropping one letter from any string. Taking the LCS of two strings only, or extending a pairwise answer, does not enforce the common third string.

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

Exams that ask this topic