Given a binary string of 0s and 1s. The task is to find the maximum difference of number of 0s and number of 1s (number of 0s – number of 1s) in the substrings of string.
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains a sting S.
For each test case, print the maximum difference in new line. In case of all 1s print "-1".
Input : S = "11000010001" Output : 6 From index 2 to index 9, there are 7 0s and 1 1s, so number of 0s - number of 1s is 6.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.