Maximum Average Subarray I
Read the lesson → understand the pattern → then code. Tutor works offline (built-in teacher); optional Cursor/Gemini keys upgrade chat quality.
Topic refresher: Sliding Window — Live Range
Maintain [L,R] that satisfies a constraint; answer from length/sum/counts.
int L = 0;
for (int R = 0; R < n; R++) {
// add s[R]
while (/* invalid */) { /* remove s[L] */ L++; }
// update answer
}EasySliding WindowLeetCode #643
Fixed window average
Sum first k, then slide: add right, remove left. Track max sum/k.
Examples
Example 1
Input
6 4 1 12 -5 -6 50 3
Output
12.75000
Example 2
Input
1 1 5
Output
5.00000
Stuck? Take a nudge
C++17Autosaves