Max Sum Subarray of Size K Visualization & Animation
Finds the maximum sum of any k consecutive elements using a fixed-size sliding window in O(n).
## What is it?
Find the maximum sum of any contiguous subarray of exactly size `k`. Fixed-size sliding window technique.
## How it works
- Compute the sum of the first `k` elements → initial window sum
- Slide the window right one position at a time:
- Add `arr[i]` (incoming right element)
- Subtract `arr[i-k]` (outgoing left element)
- Update `maxSum` if current window sum is larger
- Return `maxSum`
## When to use
- Fixed-size window sum queries
- Average of every k consecutive elements
- Foundation for variable-size sliding window problems
## Key Points
- O(n) time, O(1) space — avoid recomputing the entire window sum each time
- Classic entry-point for the sliding window pattern
- For variable window size (at most / at least k), use the two-pointer variant