Please wait
Loading technology simulations
The requested content is still loading.
Finished experimenting?
Save one completion to this browser's signed guest ledger, or directly to your account when signed in.
Please wait
Loading technology simulations
The requested content is still loading.
Save one completion to this browser's signed guest ledger, or directly to your account when signed in.
| approach | n=1K | n=1M |
|---|---|---|
| Brute Force | 2,994 | 2,999,994 |
| Sliding Window | 1,000 | 1,000,000 |
1s ← sum(a[0 .. k−1])2best ← s3for i in k .. n−1:4 s ← s + a[i] − a[i−k]5 best ← max(best, s)6return best
This sliding window simulator animates the maximum-sum-subarray-of-size-k problem two ways so you learn why the optimization works, not just the trick. Brute force re-adds all k elements for every window position (O(n·k)); the sliding window reuses the k−1 overlapping elements between consecutive windows, adding the element that enters and subtracting the one that leaves (O(n)). A translucent window glides across numbered cells, the entering cell glows green and the leaving cell red, a gold outline marks the best window found so far, and a work-to-solve card projects the operation count at n = 1,000 and n = 1,000,000 so the gap between quadratic-ish and linear scaling is concrete. A synced pseudocode panel highlights the line running each step.
sliding window technique · maximum subarray sum · fixed-size window · time complexity comparison · brute force vs optimized · O(n) vs O(n times k) · reuse overlapping work
Browse all Technology simulations →
Free to use in your browser — no signup required. Found a bug or have an idea to make it better? Tell us.