← Visualizers
Sliding Window — Variable LeetCode 1004

Max Consecutive Ones III / visualized

Same shape as Longest Substring Without Repeating Characters — right always advances, left only moves when forced to. Here "forced to" means the window contains more than k zeros — no set needed, just a running zeroCount.

Execution

idle
Press Run to begin.
0 / 0
Speed

Java · running line

in window (1) in window (0) shrinking new max
O(n) time · O(1) space  ·  zeroCount replaces the hash set — cheaper to track since we only care about a count, not identity.