Skip to content
Onsite

Palindrome Partitioning II

HardP3Coding

Cut s into consecutive pieces so that every piece is a palindrome. Return the minimum number of cuts needed. A string that is already a palindrome needs 0 cuts.

Example 1

Input
s = "aab"
Output
1
Why
Cut once to get "aa" and "b".

Example 2

Input
s = "a"
Output
0

Example 3

Input
s = "ab"
Output
1

Constraints

  • 1 <= s.length <= 2000
  • s contains lowercase English letters.

Hints

Run checks the 3 visible tests, Submit all 11.