Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
What is the length of the longest common subsequence of the three strings "ABCBDAB", "BDCABA" and "BCADB"?
- A. 4
- B. 0
- C. 5
- D. 3
Correct answer: A. 4
Use a three-dimensional DP: if the three current letters match, add 1 to the diagonal; otherwise take the best of dropping one letter from any string. Taking the LCS of two strings only, or extending a pairwise answer, does not enforce the common third string.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many non-empty subsequences of "abcbab" (chosen by index, so the same letters at different positions count as different subsequences)…
- How many index triples i < j < k in [3, 1, 4, 1, 5, 9, 2, 6] satisfy a[i] < a[j] < a[k] (strictly increasing)?
- You stand on index 0 and must reach index 7. From index i you may move to any of the next 2 indices (i+1 or i+2). Landing on index j costs…
- What is the maximum product of THREE distinct elements of [-10, -3, 1, 5, 2, -8, 4] (chosen by position)?
- The substitutions-only distance (Hamming distance) between "karolin" and "kathrin" counts positions where the letters differ. What is that…
- What is the length of the longest repeating subsequence of "aabebcdd"? It is a subsequence that appears at least twice, where the two…