Data Structures & AlgorithmsHardTCS NQT · Infosys pattern
What is the length of the longest common subsequence of "BDACDBED" and "DEEAAC"?
- A. 2
- B. 3
- C. 7
- D. 4
Correct answer: B. 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, 7.
More Coding Interview Problems questions
- 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…
- What is the length of the longest common subsequence of "ADDDBEEE" and "DDCCCCDB"?
- 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…