Sliding windows

What is the largest window sum?

Examples

Worked example

Input
[2, 5, 1, 4], window size 2
Expected output
7

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

The consecutive sums are 2 + 5 = 7, 5 + 1 = 6, and 1 + 4 = 5.

Back to the lesson