Data Structures & AlgorithmsHardGATE CS · ICPC regional

What is the length of the shortest string that has both "abcbdab" and "bdcaba" as subsequences?

  1. A. 9
  2. B. 13
  3. C. 4
  4. D. 7

Correct answer: A. 9

The shortest common supersequence keeps every common letter once and appends the remaining letters of each string: length = m + n − LCS. The LCS is the piece shared by both strings, so it is counted only once.

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

Exams that ask this topic