text. Cut it into pieces so that every piece is a palindrome, meaning it reads the same forwards and backwards. A single letter counts as a palindrome.
Return the smallest number of cuts that achieves this.text='abacdc' → 1
One cut is enough: "aba" | "cdc".
text='racecar' → 0
The whole string is already a palindrome, so no cuts are needed.
text='xyzzy' → 1
"x" | "yzzy" takes a single cut.
text consists of lowercase English letterstext='abacdc'
1
Run checks the first 3 tests in your browser. Submit checks all 161 tests on the server, hidden ones included.