Longest window after flips
Return the longest binary subarray containing at most k zeros, where k is nonnegative.
window = [1, 0, 1, 0]
k = 1
print(window.count(0) > k) # shrink leftReason about the state
Extend the right endpoint and shrink the left until the zero count fits. Each index enters and leaves the window once. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return the longest binary subarray containing at most k zeros, where k is nonnegative.
The explanation opens here once every check passes.