Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional
Problem: The string "abcbaxyzzyxq" is given. What is the minimum number of characters that must be deleted so the remaining string is a palindrome (the remaining characters keep their order)?
- A. 7
- B. 1
- C. 0
- D. 6
Correct answer: D. 6
Deletions = length − longest palindromic subsequence = 12 − 6, where the LPS is xyzzyx (abcba has only 5). Keeping the first palindrome abcba gives 7, allowing the letters to be rearranged needs only 1 deletion, and taking the LCS of s with itself instead of its reverse gives 0.
More Coding Interview Problems questions
- Problem: A string is formed by writing the letters of "kayak" then "level" then "rotor". How many substrings of length 5 of…
- Problem: Starting from the string "00000" of five zeros, operations flip a substring: each operation chooses positions l ≤ r and flips…
- Problem: The number of ways to choose 3 vertices from a graph's vertex set of size n = 12 such that no two chosen vertices are adjacent in…
- Problem: A stream of 12 numbers 5, 1, 4, 4, 2, 5, 3, 1, 2, 3, 3, 4 arrives. How many distinct values appear at least twice in the stream?
- Problem: Start with x = 5. Repeat this rule: if x is odd, set x = x + 3; if x is even, set x = 2x − 1. Count how many times the rule is…
- Problem: Starting from 0 on a number line, a frog jumps +4, then −1, then +4, then −1 and so on, alternating, for 25 jumps in total. It…