A puzzle app cuts a label s into pieces so that every piece reads the same forward and backward (a palindrome). Single letters are palindromes.
Write fewestCuts(s) that returns the fewest cuts needed so that every piece is a palindrome. A label that is already a palindrome needs 0 cuts.
Input: s = "noonabba" Output: 1
noon | abba.
Input: s = "abc" Output: 2
No two neighboring letters match, so every letter is its own piece.
1 <= s.length <= 2000s contains only lowercase English letters.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #549 Fewest Palindrome Cuts in a Label. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.