Data Structures & AlgorithmsHardTCS NQT · Infosys coding round
Problem: Using insert, delete and replace, each costing 1, what is the minimum number of operations to convert "dragon" into "lantern"?
- A. 9
- B. 1
- C. 7
- D. 6
Correct answer: D. 6
The Levenshtein DP gives 6 for dragon → lantern. Allowing only inserts and deletes gives m + n − 2·LCS = 9, counting position-by-position mismatches plus the length difference gives 7, and the length difference alone is 1.
More Coding Interview Problems questions
- Problem: How many palindromic substrings does "aabbaa" contain? Two substrings count as different if they occupy different index ranges…
- Problem: Compute the KMP prefix function (the longest proper prefix that is also a suffix, for each prefix) of the pattern "abacabab"…
- Problem: Count the occurrences of the pattern "aaa" in the text "aaabaaaab", where occurrences may overlap (each starting index that…
- Problem: Round-robin scheduling with time quantum 3 is applied to processes that all arrive at time 0: P1 needs 7 units, P2 needs 4, P3…
- Problem: Josephus game: n = 37 people stand in a circle numbered 1 to 37. Starting from person 1, every 4th person is removed (counting…
- Problem: A deque starts empty. Operations in order: pushback(5), pushfront(2), pushback(8), popfront(), pushfront(9), pushback(1)…