

Binary String is a string that consists of only ‘0’s and ‘1’s.
A string ‘A’ is said to be a substring of string ‘B’ if ‘A’ can be obtained by deleting several characters(possibly none) from the start of ‘B’ and by deleting several characters(possibly none) from the end of ‘B’.
The substring must have a length greater than or equal to 1.
The first line of input contains an integer ‘T’, denoting the number of test cases. The test cases follow.
The first line of each test case contains a binary string.
Print the maximum difference between the number of zeros and the number of ones in any substring of the given string.
Print the output of each test case in a new line.
1<= T <= 100
1 <= |S| <= 10,000
S[i] = ‘0’ / ‘1’
Time Limit: 1 sec
The idea is to check all the possible substrings and count the difference between the number of zeros and the number of ones in every substring.
The idea is to assign values to ‘0’s and ‘1’s virtually. We are assigning the value of every ‘0’ as 1, and the value of every ‘1’ as -1 since every ‘0’ will contribute 1 and every ‘1’ will contribute -1 to the answer in any substring. Hence, we are keeping the value of ‘0’ as positive and ‘1’ as negative. We are not changing the string or using a new array to store the weights. In the run time, when we’ll come across any ‘0’ or ‘1’, we’ll add or subtract according to the assigned weights.