Data Structures & AlgorithmsHardProduct-company placement

What is the length of the longest common subsequence of MARTIAN and GRAPHICAL, and how many DISTINCT longest common subsequences (as strings) are there?

  1. A. Length 3, 1 distinct
  2. B. Length 4, 2 distinct
  3. C. Length 3, 3 distinct
  4. D. Length 3, 2 distinct

Correct answer: D. Length 3, 2 distinct

The LCS table gives length 3; following every tie in the table and keeping distinct strings yields AIA, RIA.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic