My code is failing for 1 test case

I have approached this problem using sliding window and it’s failing in 1 test case . Please help. Furthermore, how will I solve this problem using recursion/dp?

@ap8730390 lemme check your submission buddy! your score is showing 100 i have checked so what’s the problem then?

As far as recursion is concerned:-
for each i, you have to call a recursive method, and there will be 2 cases:-

  • if arr[i] = 1, you will do length++
  • If arr[i] = 0 and k > 0 you will do length++ and decrement k, i.e converting 0 to 1 and adding to result.
    No its your task to find out if it satisfies dp paradigm.

If your doubt is cleared mark it resolved buddy!

But I think it’s useless to use dp here …right? Sliding window technique gives solution in O(n).

@ap8730390 Yup sliding window is way efficient. If your doubt is cleared mark it resolved!