Data Structures & AlgorithmsModerateGATE CS · TCS NQT

What is the length of the longest common subsequence of the strings "AGGTABQZ" and "GXTXAYBZQ"?

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

Correct answer: C. 5

A longest common subsequence keeps letters that are not contiguous in either string, so it is generally longer than the longest common SUBSTRING. The DP takes the max of skipping one letter from either string whenever the last letters differ.

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

Exams that ask this topic