118. Max Consecutive Ones III

Medium · Array

You have an array of 0s and 1s, and you can flip at most k zeros to ones. Find the length of the longest consecutive sequence of 1s you can create.

Input: an array `nums` containing only 0s and 1s, and an integer `k` representing the maximum number of zeros you're allowed to flip.

Return: a single integer — the maximum length of consecutive 1s achievable after flipping at most k zeros.

Examples

Example 1
Input: [[1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0], 2]
Output: 6
Explanation: Flip both zeros at indices 5 and 10 to get six consecutive 1s
Example 2
Input: [[0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1], 3]
Output: 10
Explanation: Best is to flip three zeros within a 10-wide window

Constraints