Data Structures & AlgorithmsVery hardProduct Company SDE · Amazon/Microsoft-style OA
What is the length of the longest common subsequence of "ACEACCEBD" and "DBEADDEA"?
- A. 6
- B. 4
- C. 2
- D. 3
Correct answer: D. 3
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 3. The edit distance between the same strings is a different quantity, 6.
More Coding Interview Problems questions
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- 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 "AEEBDCCC" and "BEBEADE"?
- Problem: A string s (length n) must be searched for a pattern p (length m) in text. Which algorithm guarantees O(n+m) worst-case time…
- Problem: Rabin-Karp pattern matching uses a rolling hash to compare a pattern against every window of the text. What is its typical time…