Count of substrings containing K ones
Submissions: 488   Accuracy:

21.33%

  Difficulty: Easy   Marks: 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”.

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



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.