Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 D
What is the minimum number of pieces needed to split "abacdcbaxyzyx" into contiguous pieces where every piece is a palindrome?
- A. 6
- B. 5
- C. 4
- D. 8
Correct answer: B. 5
dp[j] = 1 + min dp[i] over palindromes s[i..j−1]: this is the minimum number of pieces, which is the minimum cuts plus one. Greedily taking the longest palindrome from the left can fail, because the longest first piece may leave an awkward remainder.
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
- You may increase any element of [5, 3, 2, 10, 4] by any amount (increases only). What is the minimum total increase needed to make the…
- A path of length 9 is walked from 0 to 9: a step of 1 costs 3 and a step of 2 costs 5. What is the minimum total cost?
- A 1 × 11 strip must be covered exactly by tiles of lengths 2, 3 and 5 (tiles cannot overlap or stick out). Tile lengths 2, 3, 5 cost 4, 5…
- What is the length of the longest CONTIGUOUS block that appears in both arrays [1, 5, 3, 7, 2, 3, 7, 8] and [4, 7, 2, 3, 7, 9, 1] (equal…
- What is the minimum number of letters you must insert (into either string) so that "leetcode" and "codeleet" become anagrams of each other?
- A string of 8 brackets is "]][[][][" where '[' and ']' appear equally often. Each operation swaps any two characters. What is the minimum…