You are given a binary string \(S\) of length \(N\). A substring of a binary string is called positive if the number of \(1's\) present in the substring is strictly greater than the number of \(0's\) present. Find the number of positive substrings in the given string \(S\)
Input format
- The first line contains \(T\) denoting the number of test cases. The description of \(T\) test cases is as follows:
- For each test case:
- The first line contains \(N\) denoting the length of string \(S\).
- The second line contains the binary string \(S\).
Output format
For each test case, print the number of positive substrings in the given string \(S\)
Constraints
In the first test case, the positive substrings are \(S_{1\dots1} = 1, S_{3\dots3} = 1,S_{1\dots3} = 101.\)
In the second test case, the positive substrings are \(S_{1\dots1} = 1, S_{4\dots4} = 1,S_{5\dots5} = 1, S_{4\dots5} = 11, S_{3\dots5} = 011,S_{1\dots5} = 10011.\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor