← Visualizers
Sliding Window — Fixed LeetCode 643

Maximum Average Subarray I / visualized

Find the length-k window with the highest average. No re-summing each window — build the sum for the first k elements once, then slide: add the new element, drop the oldest one, compare.

Execution

idle
Press Run to begin.
0 / 0
Speed

Java · running line

in window just removed new max
O(n) time · O(1) space  ·  track the max sum, not the max average — divide by k exactly once, at the end.