
Flip Bits Problem Explanation
Given an array of integers ARR
of size N, consisting of 0s and 1s, you need to select a sub-array and flip its bits. Your task is to return the maximum count of 1s that can be obtained by flipping a chosen sub-array at most once.
Input:
The input consists of a single integer T
(number of test cases). For each test case:
- An integer
N
, representing the size of the array. - An array of
N
space-separated integers representing the elements of the array.
Output:
For each test case, output a single integer representing the maximum number of 1s you can have in the array after performing at most one flip operation.
Example:
Input:
T = 1
N = 5
ARR = [1, 1, 0, 0, 1]
Output:
5
Explanation:
By flipping the sub-array from index 2 to 3, the resulting array becomes [1, 1, 1, 1, 1], which contains five 1s. Hence, the output is 5.
Constraints:
1 <= T <= 100
1 <= N <= 10^4
0 <= ARR[i] <= 1
Note:
You are not required to print anything. Implement the given function to return the answer.


Given an array of 0s and 1s, find the maximum count of 1s by flipping a sub-array at most once.
Iterate through the array and keep track of the maximum count of 1s seen so far.
If the current element is...read more

Top Infosys System Engineer Specialist interview questions & answers
Top HR questions asked in Infosys System Engineer Specialist
Reviews
Interviews
Salaries
Users/Month