What is the error in my recursive code of this question
You got 100 score for this problem. please mark it as resolved.
My question is not about the score .Its about recursive code! Can you help me find the error in recursive code?
try to dry run your code for sample test code and then try to dry run this you will understand where you were doing wrong.
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 THINK YOU HAVENT EVEN OPENED MY CODE AND CHECKED.I HAVE NOT USED ANYTHING LIKE A LEFT AND RIGHT POINTER.
@Monu-Singh-480654572341490 can you help me here?
I went through your code and told you to debug.You cant expect direct answer.
If u tried to debug you would see that your
int ans=count(arr, i + 1, k)+1;
keeps on moving forward till you have i=10 and u get 1+1+1+…=10 as your answer .so your logic is incorrect
the correct approach is using
Sliding Window for the given array. use a window covering from index Left to index Right. Let the number of zeros inside the window be zeroCount. We maintain the window with at most m zeros inside.
- While zeroCount is no more than m: expand the window to the right and update the count zeroCount.
- While zeroCount exceeds m, shrink the window from left , update zeroCount;
- Update the widest window along the way. The positions of output zeros are inside the best window.