Palindrome Partitioning II - Problem
Given a string s, partition s such that every substring of the partition is a palindrome.
Return the minimum number of cuts needed for a palindrome partitioning of s.
A palindrome is a string that reads the same backward as forward.
Input & Output
Example 1 — Basic Partition
$
Input:
s = "aab"
›
Output:
1
💡 Note:
The string can be partitioned as "aa|b". "aa" and "b" are both palindromes, requiring only 1 cut.
Example 2 — Already Palindrome
$
Input:
s = "aba"
›
Output:
0
💡 Note:
The entire string "aba" is already a palindrome, so no cuts are needed.
Example 3 — Multiple Cuts Needed
$
Input:
s = "abcde"
›
Output:
4
💡 Note:
Each character must be its own partition: "a|b|c|d|e", requiring 4 cuts.
Constraints
- 1 ≤ s.length ≤ 2000
- s consists of lowercase English letters only
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code