Practice · 5 of 5
Maximum k-Sum Window
CHALLENGE
Difficulty: intermediate+25 XP
**Description:** Given n numbers, find the maximum sum of any k **consecutive**
numbers (a fixed window, not any subset).
**Input:** Line 1: n k (1 ≤ k ≤ n ≤ 10^5). Line 2: n numbers (−10^9..10^9).
**Output:** One integer.
**Example:** 5 2 / 3 -1 4 2 0 → 6 (window 4+2).
*Note:* an O(n·k) double loop passes only small n here — but the sliding
sum (add the new element, drop the old) is O(n). Try both; one times out
at n = 10^5.
Press Submit to check your solution.
Back to lesson: Practice: Array Mechanics Set