Given a string s, partition it such that every substring of the partition is a palindrome. Return the minimum number of cuts needed.
Use dynamic programming. First precompute a 2D isPalin[i][j] table. Then use dp[i] = minimum cuts for s[0..i]. For each i, if s[0..i] is a palindrome dp[i]=0; otherwise dp[i] = min over all j where s[j+1..i] is a palindrome of dp[j]+1.
- Precompute isPalin[i][j] using DP: isPalin[i][j] = s[i]==s[j] && isPalin[i+1][j-1].
- Initialize dp[i] = i (max cuts = i for length i+1 prefix).
- For each i, if isPalin[0][i], set dp[i]=0.
- Otherwise, for each j from 1 to i, if isPalin[j][i], set dp[i] = min(dp[i], dp[j-1]+1).
- Time Complexity: O(N^2)
- Space Complexity: O(N^2) — isPalin table