Hackers with Bits
Practice
3.9 (101 votes)
Approved
Basic programming
Easy
Problem
91% Success 33443 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Hackers love bits, so does Alex. Alex has just started his career as hacker and found a special binary array A (containing \(0s\) and \(1s\)).

In one operation, he can choose any two positions in the array, and can swap their values. He has to perform exactly one operation and maximize the length of the subarray containing only \(1s\).

Note: The positions can be different or same.

As Alex is a newbie in his field, help him for the same, and output the required length of the sub array containing only \(1s\).

Input Format:

First line consists of one integer N, denoting the number of elements in the array.

Second line consists of N space-separated integers, denoting the elements of the array.

Output Format:

Print the required length of the sub array containing only \(1s\).

Input Constraints:
\(1 \le N \le 100\)
\(0 \le A[i] \le 1\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
38 votes
Tags:
Basic ProgrammingBasics of ImplementationCakewalkEasyImplementation
Points:20
9 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementationString Manipulation
Points:30
2 votes
Tags:
MediumPrime FactorizationMathematicsOpenApprovedFactorization