Data Structures & AlgorithmsHardGATE CS · ICPC regional
How many non-empty distinct palindromic partitions, i.e. ways to split the string aabb into contiguous pieces where every piece is a palindrome, exist?
- A. 5
- B. 2
- C. 7
- D. 4
Correct answer: D. 4
Use dp[j] = sum of dp[i] over all i where s[i:j] is a palindrome. Splits such as aa|bb and a|a|bb both count as distinct partitions.
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 distinct non-empty subsequences (as strings) does the word aba have?
- A print queue holds jobs with priorities [2, 1, 3, 2] (index 0 to 3). The front job prints only if no waiting job has a higher priority…
- A stack machine runs PUSH 3, PUSH 4, ADD, PUSH 5, MUL in order. The result is the value on top of the stack at the end. What is it?
- How many index pairs i < j in the array [1, 3, 1, 2, 3, 3] have a[i] = a[j]?
- What is the sum of the XOR of every non-empty contiguous subarray of [1, 2, 3]?
- How many contiguous subarrays of [2, 4, 8, 3, 6] have an LCM equal to their maximum element?