Data Structures & AlgorithmsHardGATE CS
What is the minimum number of characters that must be inserted anywhere in "CBAABDCABBDAC" to make it a palindrome?
- A. 4
- B. 5
- C. 8
- D. 6
Correct answer: B. 5
The answer is n − (length of the longest palindromic subsequence) = 13 − 8 = 5. The value 8 itself is the length of the palindromic subsequence, not the number of insertions.
More Coding Interview Problems questions
- 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?
- How many integers n with 1 <= n <= 100000 are divisible by exactly one of the numbers 6, 10 and 15?