bits consists of zeros and ones. You may turn at most one zero into a one.
Return the greatest length of a contiguous stretch of ones you can obtain.
Follow-up: how would you solve it if the numbers arrive one at a time as a stream and you cannot store them all?bits=[1, 1, 0, 1, 0, 1, 1, 1] → 5
Fixing the second zero gives [1, 1, 0, 1, 1, 1, 1, 1], five ones in a row. Fixing the first one gives only four.
bits=[0, 0, 0] → 1
One position can become a 1, so the length is 1.
bits=[1, 1, 1] → 3
bits=[1, 1, 0, 1, 0, 1, 1, 1]
5
Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.