Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
What is the minimum number of cuts needed to split "abbacdcdc" into pieces that are each a palindrome?
- A. 8
- B. 6
- C. 4
- D. 7
Correct answer: D. 7
Let pal[i][j] say whether s[i..j] is a palindrome, and cut[j] = min over i of cut[i−1] + 1 whenever s[i..j] is a palindrome (with cut = 0 if the whole prefix is one palindrome). Cutting between every letter is the trivial upper bound, which is n − 1.
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
- What is the length of the shortest string that has both "abcbdab" and "bdcaba" as subsequences?
- How many DIFFERENT non-empty subsequences does the string "abcabc" have? Two subsequences are different if their letter sequences differ.
- How many subsequences (chosen by index) of "aabbabcaccb" spell exactly the word abc?
- Strings "ab" and "cde" are interleaved, keeping the internal order of each string. How many distinct strings can be formed this way?
- You may delete characters from "sea" and from "eat" to make the two strings equal. Deleting a character costs its ASCII code (for example…
- What is the length of the longest subsequence of [1, 7, 4, 9, 2, 5, 3, 8] whose consecutive differences alternate in sign (each step goes…