Data Structures & AlgorithmsHardGATE CS
Find the length of the longest common subsequence of X = "AGGTABQXZRYWM" and Y = "GXTXAYBZQMWRY".
- A. 7
- B. 6
- C. 8
- D. 4
Correct answer: A. 7
Standard LCS dynamic programming gives 7. The longest common substring is only 2, so confusing subsequence with substring undershoots badly.
More Coding Interview Problems questions
- What is the minimum number of characters that must be inserted anywhere in "CBAABDCABBDAC" to make it a palindrome?
- Matrices A1…A7 have dimensions 5×10, 10×3, 3×12, 12×5, 5×50, 50×6, 6×8. What is the minimum number of scalar multiplications needed to…
- A 2 × 11 board is tiled completely using 1 × 2 dominoes (placed either way) and 2 × 2 squares. How many different tilings are there?
- The 3 × 3 grid graph (9 vertices, 12 edges) has a diagonal edge added between its top-left corner and its centre vertex, giving a 13-edge…
- 50 people stand in a circle numbered 1 to 50. Starting the count at person 1, every 7th person (counting the first as 1) is removed, and…
- How many subsets of {1, 2, ..., 15} (including the empty set) contain no two consecutive integers and have an even sum?