Data Structures & AlgorithmsHardProduct Company SDE · string DP
Problem: What is the minimum number of insertions and deletions needed to turn 'abc' into 'adc'? (Only insertions and deletions are allowed, no substitutions.) Use the LCS-based formula len(a) + len(b) - 2 LCS, with LCS('abc','adc') = 2.
Problem: What is the minimum number of insertions and deletions needed to turn 'abc' into 'adc'? (Only insertions and deletions are allowed, no substitutions.) Use the LCS-based formula len(a) + len(b) - 2 * LCS, with LCS('abc','adc') = 2.
a, b = 'abc', 'adc' lcs = 2 print(len(a) + len(b) - 2 * lcs)What is printed?
- A. 2
- B. 1
- C. 3
- D. 4
Correct answer: A. 2
Delete b and insert d (2 operations) keeps the common subsequence 'ac'. A substitution would be a single operation, so this case differs from plain edit distance.
More Coding Interview Problems questions
- Problem: What is the longest common prefix of the list ['flower', 'flow', 'flight']? Run the code. python import os…
- Problem: What does the following print? python print(' '.join('the sky is blue'.split()[::-1]))
- Problem: Which statement about Hall's theorem for a bipartite graph with sides L and R is correct?
- Problem: Which claim about the complexity of deciding 2-SAT (satisfiability of clauses with at most two literals) is correct?
- Problem: Which of the following problems is NP-complete (decision version)?
- Problem: For Dijkstra on a graph with V vertices and E edges, which pairing of data structure and running time is correct?