Lv.4dpstring
Palindrome Partitioning Min Cuts
- Memory limit
- 256 MB
- Correctness time limit
- 10000 ms
- Solvers
- 0
Return the minimum number of cuts so that every piece of s is a palindrome (0 if s already is one).
Examples
| s | result |
|---|---|
"aab" | 1 |
"racecar" | 0 |
"abcd" | 3 |
Efficiency
This problem has performance tests. Judge the required time complexity from the input sizes in the constraints.
Function signature
solution(s: string) → int
Constraints
-
s.length, lowercase letters only
Expected complexity
- Time
- O(N^2)
- Space
- O(N)
Examples
| s | Expected |
|---|---|
"aab" | 1 |
"racecar" | 0 |
"abcd" | 3 |
Hint
Hint
cut[i] = min(cut[j] + 1) over palindromic s[j..i). Generate palindromes by expanding around each center (updating cut
directly) or precompute a palindrome table, for . Checking each piece directly is .
Time limits per language
| Language | Efficiency time limit | |
|---|---|---|
| C (GCC, gnu17) | 200 ms | estimated |
| C++ (GCC, gnu++23) | 200 ms | derived |
| Python 3.13 | 1000 ms | derived |
| Java 25 | 1000 ms | derived |
| Kotlin 2.4 (JVM) | 1400 ms | estimated |
| C# 14 (.NET 10) | 1400 ms | estimated |
Test groups
| Group | Weight | Tests | Visibility |
|---|---|---|---|
| sample | 0 | 3 | inputs and outputs |
| correctness | 40 | 7 | verdict only |
| performance | 60 | 4 | verdict only |