Given a string of 0's and 1's. Find maximum number of pair of adjacent elements that can be removed from the string to remain string valid with the following condition.
1.) If two adjacent element are 0 and 1 or different remove them.
2.) But, If after removing their adjacent elements are same, string becomes invalid.
3.) Empty string is valid.
Input:
string = "1100"
Output:
2
Explanation:
First Remove char c2 and c3 .
After removing string becomes "10", valid.
Again Remove char c1 and c2.
Now, string is empty, and answer is 2.
Input:
string = "110100"
Output:
3
Explanation:
1.) Remove char c3 and c4 , string becomes "1100" valid.
2.) Remove char c2 and c3 , string becomes "10" valid.
3.) Remove char c1 and c1 , string becomes "" valid.
So, the maximum possible answer is 3.
Input:
string = "1101110"
Output:
1
Explanation:
1.) Remove char c6 and c7 , string becomes "11011" valid.
Now, we cant remove any pair.
So, the maximum possible answer is 1.