Junior — Middle+
Longest continuous segment of ones after removing one element
livecode
Task condition
Given an array containing only 0s and 1s. It is required to determine the maximum number of consecutive ones that can be obtained by removing exactly one arbitrary element from the array.
assert(maxOnes(new int[]{1, 1, 0, 1})) == 3
assert(maxOnes(new int[]{1, 1, 0, 0, 1})) == 2