Introduction
Data Structures play a vital role in our problem-solving skills. Consistency with an efficient learning approach can raise your bar in the programming world.
This problem is about counting k length subarrays with only 1’s in the binary(0,1) string.
What do you mean by subarray?
It is a contiguous part of array. For example the array [1, 2, 3, 4].The subarrays are (1), (2), (3), (4), (1,2), (2,3), (3,4), (1,2,3), (2,3,4) and (1,2,3,4).
For questions related to each data structure, refer to the blog Must-Do Coding Interview Questions for Product Based Companies.
Let’s move to our problem statement for better clarity of the problem.
Problem Statement
We are given a binary string, and we aim to find the count of subarrays of length K that contains only 1.
Let’s understand this with some examples:
Example1:
Input: s= “1111110” K= 3
Output: 4

Example2:
Input: s= “100001” K= 1
Output: 2





