Skip to main content

Practice · 5 of 5

Maximum Window

CHALLENGE
Difficulty: intermediate+25 XP

**Description:** Given n integers and a window length k, find the maximum possible sum of k consecutive elements. **Input:** Line 1: n k (1 <= k <= n <= 2*10^5). Line 2: n integers (-10^9 <= a_i <= 10^9). **Output:** One integer — the maximum window sum. **Example:** 6 3 / 2 -1 4 3 -2 5 -> 6 (window -1 4 3 or 3 -2 5... compute: -1+4+3 = 6).

Back to lesson: Practice: Prefix Sum Problem Set