how can we solve this question using recursion and memorization
1 count problem
hello @ajayrajsingh_817
ur dp state should be.
dp[i][j] -> longest possible subarray of length one when only first i numbers are considerd and when only j flips are allowed.
but it will have very high time complexity.
to solve it in O(n) . try to use 2 pointers technique in it.
can you explain the logic of printing of an modified array
While using the 2 pointer/moving window approach, you can simple maintain two variables which store the left and right of the largest window, i.e they are updates every time max_length is updated.
Then afterwards, you can simply iterate between these max_indexes, and mark all as 1 and print the array.
can you plzz modified code and add logic in comment
samjh nhi aya apne jo bola
why you modified array from maxLengthl to maxLengthr by 1
we know na that from maxlenl to maxlenr , each element is going to be one. after making atmost k flips
that why i made it 1.