Data Structures & AlgorithmsHardGATE CS · TCS NQT

What is the minimum number of single-character insertions, deletions and substitutions needed to turn "sunday" into "saturnday"?

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

Correct answer: A. 3

This is the edit (Levenshtein) distance: dp[i][j] = dp[i-1][j-1] if the characters match, otherwise 1 + min(insert, delete, substitute). Counting only insertions and deletions gives m + n − 2·LCS, which is larger whenever substitution would have helped.

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

Exams that ask this topic