text of the letters a, b and c. You may repeat the following move any number of times, including zero:
- pick a non-empty beginning of the string made of one repeated letter;
- pick a non-empty ending of the string made of one repeated letter;
- the two pieces must not overlap, and they must use the same letter;
- delete both pieces.
Return the smallest length the string can be cut down to.text="bacab" → 1
Trim "b" from both ends, then "a", leaving "c". A single letter cannot serve as both the front and the back piece, so the answer is 1.
text="abbba" → 0
Trim "a" and "a" to get "bbb", then take "b" from the front and "bb" from the back, and the string is empty.
text="ccbacc" → 2
Trim "cc" and "cc" to get "ba". Its ends differ, so nothing more can be cut.
text consists only of the letters a, b and ctext="bacab"
1
Run checks the first 3 tests in your browser. Submit checks all 139 tests on the server, hidden ones included.