Trains the technique from
LeetCode 2472Maximum Number of Non-overlapping Palindrome SubstringsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A ribbon ribbon holds lowercase letters. A piece is a stretch of neighbouring letters that reads the same forwards and backwards and is at least k letters long.
Cut out as many pieces as possible so that no two of them share a letter of the ribbon.
Return the largest number of pieces that can be cut.
Example 1
Cut the first two letters and then the last two. Three pieces of two letters could never fit inside four letters.
Example 2
No two neighbouring letters match, so the only stretch reading the same both ways and long enough is the whole ribbon.
Example 3
The two letters differ, so the ribbon holds no two-letter stretch reading the same both ways.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_palindromes(ribbon: str, k: int) -> int:public int maxPalindromes(String ribbon, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.