Data Structures & AlgorithmsHardGATE CS · ICPC regional
What is the minimum number of cuts needed to partition the string abacdcdad into palindromic pieces?
- A. 2
- B. 3
- C. 1
- D. 4
Correct answer: A. 2
Use a palindrome table plus a DP over prefixes: dp[j] is the minimum cut count for the prefix ending at j, which is the minimum over palindromic last pieces. Cutting greedily from the left is not always optimal.
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 times does the pattern aba occur in ababababa when occurrences may overlap?
- For the string aabaaabaa, what is the sum of the Z-function values Z[1] + Z[2] + ... + Z[n-1] (Z[i] is the longest common prefix of the…
- How many distinct substrings of length 3 does the string abcabcabd have?
- How many substrings of abcabcbb contain no repeated character?
- Evaluate the postfix (reverse Polish) expression 5 1 2 + 4 + 3 -. What is the value?
- Array [5, 2, 8, 1, 9, 3] is processed in one left-to-right pass: each node is deleted if its value is strictly greater than the value of…