Quant Memo
Coding/●●●●●

Longest winning streak after erasing k losing days

A desk's daily results are a binary array: 1 for a winning day, 0 for a losing day. You are allowed to erase (flip to a win) at most k losing days. Find the length of the longest run of consecutive wins you can create.

days = [1, 1, 0, 1, 0, 1, 1, 0, 1], k = 2
-> 7           # erase the two 0s among days 3..8 (indices 2 and 4)

Return the maximum achievable streak length. Aim for O(n)O(n).

Show a hint

A window is "achievable" as an all-win streak exactly when it contains at most k losing days. That is a monotone constraint.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions