You are given a string s that contains only the characters 'a' and 'b'. In one move, you are allowed to delete any subsequence of the string as long as that subsequence forms a palindrome.
Your goal is to remove all characters from the string using the minimum number of such operations.
A subsequence is a sequence that can be formed by deleting some characters without changing the order of the remaining ones.
A palindrome reads the same forward and backward.
Return the minimum number of operations needed to completely delete the string.
Input: s = "aaaa"
Output: 1
Explanation:
The entire string is a palindrome, so removing it once is enough.
Input: s = "baba"
Output: 2
Explanation:
One possible sequence: Step 1: remove "bbb" (palindrome subsequence → actually "bab"). Step 2: remove the remaining "a".
Input: s = "ababbab"
Output: 2
Explanation:
Step 1: delete "ababba" (palindromic subsequence). Step 2: delete the last "b".
Accepted:
Submission: