What is the mistake?

try the following sample case
10 2
1 0 0 1 0 1 0 0 0 1

what must be the correction?

i have corrected some now the length i am getting is correct but array is not…what should be the correction in my code?

compare the length of ones with max lenght one’s subarray, if it is more update the left and right pointer and then print the same array from 0 to leftpointer print 1 from left to right pointer and from right pointer to end print the same array.

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.