Login

All Problems

Problem title

Difficulty

Avg time to solve

First Missing Positive

Moderate

18 mins

Maximum Subarray Sum

Hard

35 mins

XOR Query

Moderate

10 mins

Rat In a Maze All Paths

Moderate

40 mins

Reverse Blocks

Hard

56 mins

Sudoku?

Moderate

40 mins

Swap Two Numbers

Easy

10 mins

Flip Bits

Easy

15 mins

Add Two Numbers As Linked Lists ll

Moderate

10 mins

Alien dictionary

Hard

46 mins

Problem

Submissions

95

Avg. time to solve

15 min

Success Rate

85%

Problem Statement

```
If you are given an array {1, 1, 0, 0, 1} then you will have to return the count of maximum one’s you can obtain by flipping anyone chosen sub-array at most once, so here you will clearly choose sub-array from the index 2 to 3 and then flip it's bits. So, the final array comes out to be {1, 1, 1, 1, 1} which contains five ones and so you will return 5.
```

```
The first line of input consists of a single integer T denoting the total number of the test case.
The first line of each test case contains an integer N, which represents the array's size.
The second line of each test case contains N space-separated integers representing the array elements accordingly.
```

```
For each test case, return a single integer representing the maximum number of 1's you can have in the array after at most one flip operation.
```

```
You don’t have to print anything; it has already been taken care of. Just implement the given function.
```

```
1 <= T = 100
1 <= N <= 10^4
0 <= ARR[i] <= 1
Time Limit: 1 sec
```

```
3
5
1 0 0 1 0
4
1 1 1 0
5
0 0 1 0 0
```

```
4
4
4
```

```
For the first test case:
We can perform a flip operation in the range [1,2]. After the flip operation, the array is: 1 1 1 1 0
and so the answer will be 4
Similarly, in the second test case :
We can perform a flip operation in the range [3,3]. After the flip operation, the array is: 1 1 1 1
and so the answer will be 4.
Finally for the third test case :
We can perform a flip operation in the range [0,4]
After the flip operation, the array is: 1 1 0 1 1
and so the answer will be 4
```

```
3
5
0 0 0 0 0
5
1 1 1 1 1
8
1 0 1 0 1 0 1 0
```

```
5
5
5
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code