Longest ones after flips

Write codeMedium20 min

Your task

Given a binary array a (values 0 or 1) and an integer k, return the length of the longest contiguous subarray containing only 1s after flipping at most k zeros to ones. k is non-negative; the array may be all zeros.

Examples

longest_ones_k_flips(a: list[int], k: int) -> int
Example 1
Inputlongest_ones_k_flips([1, 1, 0, 0, 1, 1, 1, 0, 1], 2)
Output7