 Maximum difference of zeros and ones in binary string
##### Submissions: 1711   Accuracy: 41.69%   Difficulty: Easy   Marks: 2

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.

Input:
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.

Output:
For each test case, print the maximum difference in new line. In case of all 1s print "-1".

Constraints:
1<=T<=100
1<=|string length|<=105

Example:
Input:
2
11000010001
1111

Output:
6
-1

Explanation:

```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.
```

#### ** For More Input/Output Examples Use 'Expected Output' option **

Author: arun03

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.