CHALLENGES DP-3:SUBARRAY OF 1'S

PROBLEM:Given an array of size n with 0s and 1s , flip at most k 0s to get the longest possible subarray of 1s.

Input Format
First Line : n, size of array and k Second Line : n space separated numbers (0s or 1s)

Constraints
n <= 10^5 0 <= k <= n

Output Format
First Line : Size of subarray Second Line : Array after flipping k 0s

Sample Input
10 2
1 0 0 1 0 1 0 1 0 1
Sample Output
5
1 0 0 1 1 1 1 1 0 1

solution:https://ide.codingblocks.com/s/235768
//all the testcases not giving correct ans,few are giving AC,few are not.Help me to solve the problem with this code

hey ur logic in the solve function is incorrect


you can look at the logic here
l and r both start from zero and check for each value if zero increment the count of zeroes
while zero count>k increment left, if zero decrement zero count
the major mistake is here
update the max and optimum length of ones only when a new better one is found, ur updating it always, which is not to be done, since it will not give the right answer and also it will give the last one and not the first one