Data Structures & AlgorithmsModerateProduct-company MCQ pattern

What is the length of the longest common subsequence of ALGORITHM and LOGARITHM?

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

Correct answer: D. 7

Both words end in RITHM, and before it ALGO and LOGA share two letters in order (L O or L G), so the LCS is 7 (e.g. LORITHM). The longest common substring is only RITHM (5), 4 is the insert/delete distance 18 − 2·7, and 2 is the ALGO/LOGA part alone.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic