Data Structures & AlgorithmsHardProduct Company SDE · CP practice
What is the length of the longest common subsequence of "CBEDDDE" and "BEDECCBB"?
- A. 4
- B. 5
- C. 6
- D. 3
Correct answer: A. 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
- 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…
- Merging overlapping intervals (sort by start, merge when the next interval's start is ≤ the current merged interval's end — touching…
- 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 "DADADEECA" and "BADABAD"?