![]() |
VOOZH | about |
Given a Binary String s (the string that contains only 0's and 1's). Find the minimum number of palindromic subsequences that are needed to be removed such that string s becomes empty.
Examples :
Input: s = "10001"
Output: 1
Explanation: We can remove whole s, as s is already a palindrome.Input: N = 8, S = "10001001"
Output: 2
Explanation: First we'll remove sub-sequence "111" and then "00000".
The idea is based on the observation that if the entire binary string is already a palindrome, it can be removed in a single operation. If it is not a palindrome, the answer is always
2because all occurrences of one character (0or1) can be removed in one operation and all occurrences of the other character can be removed in another operation.
0121