What is the problem in this code value of largest subarray is correct but subarray is not

Your code has bugs and don’t cover edge cases!
try for k=0
You can look at my code, using deque makes it more easy

why to push_back i in 47 and 48 line

if current element is 1, then simply push it into deque, else if we can change this 0 to 1(k>0) then we convert it to 1, decrement k and push it… otherwise we start removing from front of deque until we encounter 0(so that this 0 which was converted to 1,can now be used to convert current 0).

we have to push the current element into our deque always if possible.