Data Structures & AlgorithmsHardProduct Company SDE · Infosys OA

Problem: What is the minimum number of insertions plus deletions needed to convert "heap" into "pea" if only insertions and deletions are allowed (no replacement)?

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

Correct answer: C. 3

With only insertions and deletions, the cost is len(a) + len(b) − 2·LCS. Allowing replacement would give the smaller Levenshtein distance.

More Coding Interview Problems questions

Exams that ask this topic