Flipping coins

Gary has an array of N coins some have head side up and others have the tail side up. Now Gary wants to flip exactly one interval of coins (i.e. continuous subarray) so that he can get maximum number of head side up coins.

Return the maximum number of head side up coins Gary can get after flipping exactly one interval of coins.

Input Format :

Line 1 : An integer N denoting size of array.

Line 2 : Array elements, 0's and 1's where 1 denotes coin with head side up and 0 denotes coin with tail side up.

Note : Assume input is 1 - indexed based i.e. indexing in array starts from 1 instead of 0.
Sample Input :
0 1 0 1 0
Sample Output :

Login to submit your solution

Fb dab53a1a64929320dc7425896aa73fd9e5512b6ab52e414ff5f3ebb5cecc73eb

Share Problem