Data Structures & AlgorithmsHardTCS NQT · Infosys pattern
What is the length of the longest common subsequence of "ADDDBEEE" and "DDCCCCDB"?
- A. 3
- B. 5
- C. 4
- D. 7
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, 7.
More Coding Interview Problems questions
- 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: 8 servers are joined by cables one at a time. Count the connected groups at the end and how many cables were redundant (joined…
- 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…
- 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…
- 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…