Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Build the initial window by summing the first k elements. Then slide the window one position at a time: add the new right element and subtract the element that falls off the left. Track the maximum sum seen across all window positions.
Each window position differs from the previous by exactly one element added and one removed. By maintaining a running sum, we avoid recomputing the entire sum for each position, reducing the work from O(n*k) to O(n).
Updated Feb 2026