Max Consecutive Ones III

Problem Given a binary array and an integer B, find the longest contiguous run of 1s achievable by flipping at most B zeros.

Input / Output

  • Input: int array A (0/1), int B. Output: max window length.

Constraints

  • n up to 10^5; O(n) expected.

Example

  • A = [1,0,0,1,1,0,1], B = 1 → 4 ([1,1,0,1] flipping the single 0); B = 2 → 6.
asked …
LeaderboardSalaryAccount