Count problem challange

how to approach this problem

An Efficient Solution can solve the problem in O(n) time and O(1) space. The idea is to use Sliding Window for the given array. The solution is taken from here. Let us use a window covering from index wL to index wR. Let the number of zeros inside the window be zeroCount. We maintain the window with at most m zeros inside.

The main steps are:

While zeroCount is no more than m: expand the window to the right (wR++) and update the count zeroCount.
While zeroCount exceeds m, shrink the window from left (wL++), update zeroCount;
Update the widest window along the way. The positions of output zeros are inside the best window.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.