Given a binary array **A** of size **N** and an integer **M**. Find the maximum number of consecutive 1's produced by flipping at most M 0's.

**Input:**

The first line contains an integer T denoting the total number of test cases. In each test cases, the first line contains an integer N denoting the size of array. The second line contains **N** space-separated integers A_{1}, A_{2}, ..., A_{N} denoting the elements of the array. Third line consists of an integer m that is maximum number of flips allowed.

**Output:**

Output the maximum numbers of consecutive 1's.

**Constraints:**

1 <= T <= 10^{3}

1 <= N <= 10^{7}

0 <= M <= N

0 <= A_{i} <= 1

**Example:**

**Input:**

1

11

1 0 0 1 1 0 1 0 1 1 1

2

**Output:**

8

**Explanation:
Testcase 1:** Maximum subarray is of size 8 which can be made subarray of all 1 after flipping two zeros to 1.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

thanuvinu94 | 425 |

the_coder95 | 380 |

RishabhTanwar1 | 280 |

shubham3174 | 208 |

RitikRosan | 202 |

the_coder95 | 1226 |

RishabhTanwar1 | 1000 |

thanuvinu94 | 634 |

tathagat289 | 628 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4885 |

Quandray | 4547 |

Login to report an issue on this page.