GATE Computer ScienceVery hardGATE CSE · ISRO

Strings X = ABCBDABA and Y = BDCABAB are given. How many distinct longest common subsequences (distinct as strings) do they have?

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

Correct answer: C. 3

The LCS length is 5 and the DP back-trace (taking both branches on ties and de-duplicating) yields 3 different strings: BCABA, BCBAB, BDABA.

More Programming and Data Structures (GATE) questions

Exams that ask this topic