All mock tests are FREE till 31 December — register to save your progress

The longest common subsequence of {1,2,3,2,4,1,2} and {2,4,3,1,2,1} is

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: C. 2,3,2,1

Explanation

2,3,2,1 appears in order in both sequences (1,2,3,2,4,1,2 and 2,4,3,1,2,1) and the LCS length is 4. 2,1,2,3 and 1,3,2,1 are not subsequences of the second sequence, and 2,3,1,2,1 is not a subsequence of the first.

More Data Structures and Algorithms questions