Data Structures & AlgorithmsHardProduct Company SDE · Infosys OA

Problem: The longest common subsequence of "ABCBDAB" and "BDCABA" has length L. What is L?

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

Correct answer: C. 4

The LCS table takes the diagonal plus one on a match and the maximum of its neighbours otherwise. Using the longest common substring (contiguous) instead gives a smaller value.

More Coding Interview Problems questions

Exams that ask this topic