Data Structures & AlgorithmsHardGATE CS · ICPC regional

What is the length of the longest common subsequence of AGGTAB and GXTXAYB (letters need not be contiguous)?

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

Correct answer: A. 4

A subsequence common to both strings is GTAB. The DP over prefix pairs gives the length; using longest common substring gives a smaller value.

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

Exams that ask this topic