Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
What is the Levenshtein edit distance (insert, delete, substitute all cost 1) between "DAABDB" and "BCDCEBDB"?
- A. 12
- B. 4
- C. 6
- D. 2
Correct answer: B. 4
DP: d[i][j] = min(d[i−1][j]+1, d[i][j−1]+1, d[i−1][j−1]+[s_i≠t_j]) → 4. The indel-only distance 6 forbids substitution.
More Coding Interview Problems questions
- Problem: 7 servers are joined by cables one at a time. Count the connected groups at the end and how many cables were redundant (joined…
- What is the length of the longest common subsequence of "BDACDBED" and "DEEAAC"?
- Fractional knapsack, capacity 18 (items can be split). Items (weight, value): (6, 11), (5, 10), (3, 15), (6, 5). Using the greedy…
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- Using a min-heap of size k (push each element, pop when size exceeds k, so the heap always holds the k largest seen so far), what is the k…
- Problem: Dijkstra's algorithm (array-based, pick the unvisited vertex with smallest tentative distance each round) computes shortest…