Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@shashi1iitk | 398 |

@Suniti Jain | 114 |

@ankish2000nayak | 104 |

@gopalsethlnct | 94 |

@esmadhan | 90 |

@senthil1185 | 90 |

@gyanadipta07 | 89 |

@satwikdash2000 | 85 |

@varunmishra3040 | 83 |

@gamec1634 | 82 |

@pj_1721 | 80 |

Complete Leaderboard |

Given an array **arr[]** consisting of **0’s** and **1’s**. A flip operation is one in which you turn 1 into 0 and a 0 into 1.You have to do atmost one “Flip” operation of a subarray. Then finally display maximum number of 1 you can have in the array.

**Input:**

The first line of input consist of a single integer **T** denoting the total number of test case. First line of test case contains an integer N size of array. Second line of test case contains N space separated integers denoting the array arr[].

**Output:**

For each test case output a single integer representing the maximum number of 1's you can have in the array after atmost one flip operation.

**Constraints:**

1 <= T = 100

1 <= N <= 10^{4}

0 <= arr[i] <= 1

**Example:
Input:**

1

5

1 0 0 1 0

**Output:**

4

**Explanation:**

We can perform a flip operation in the range [1,2]

After flip operation array is : 1 1 1 1 0

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Flip Bits

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.