Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
What is the length of the longest common subsequence of "BEADCBBDA" and "BAAEDC"?
- A. 3
- B. 5
- C. 4
- D. 6
Correct answer: C. 4
The DP table d[i][j] = d[i-1][j-1]+1 on a match, else max of the two neighbours, gives an LCS length of 4. The edit distance between the same strings is a different quantity, 6.
More Coding Interview Problems questions
- A divide-and-conquer routine satisfies T(n) = 8T(n/2) + n². What is its running time (by the master theorem, extended for polylog terms…
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- What is the length of the longest common subsequence of "CBEDDDE" and "BEDECCBB"?
- Fractional knapsack, capacity 13 (items can be split). Items (weight, value): (8, 8), (3, 4), (6, 13), (8, 10), (6, 6). Using the greedy…
- 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…
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…