Count of substrings containing K ones
Easy Accuracy: 25.33% Submissions: 695 Points: 2

Given a binary string and an integer K, the task is to count the number of substrings which contains exactly K ones.

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 binary string and an integer K.

Output:
For each test case, print the count of substrings in new line.

Constraints:
1<=T<=200
0<=K<=20

1<=|String length|<=105

Example:
Input:
2
10010 1
100101 2

Output:
9
5

Explanation:

Input : s = “10010”
        K = 1
Output : 9
The 9 substrings containing one 1 are,
“1”, “10”, “100”, “001”, “01”, “1”, 
“10”, “0010” and “010”.

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.