Max Consecutive Ones III

Read the lesson → understand the pattern → then code. Tutor works offline (built-in teacher); optional Cursor/Gemini keys upgrade chat quality.

Topic refresher: Sliding Window — Live Range

Maintain [L,R] that satisfies a constraint; answer from length/sum/counts.

int L = 0;
for (int R = 0; R < n; R++) {
    // add s[R]
    while (/* invalid */) { /* remove s[L] */ L++; }
    // update answer
}
Sliding Window

Max Consecutive Ones III

Medium
LeetCode
5/6
MediumSliding WindowLeetCode #1004

Max Consecutive Ones III

Longest window with at most k zeros (you may flip them).

Examples

Example 1

Input

11 2
1 1 1 0 0 0 1 1 1 1 0

Output

6

Stuck? Take a nudge

C++17