Maximum window sum

Write codeEasy15 min

Your task

Given a stream of integers and a window size k, return the maximum sum of any contiguous window of exactly k elements. If k is not a positive integer or is larger than the stream length, return -1. The stream may contain negatives.

Examples

max_window_sum(stream: list[int], k: int) -> int
Example 1
Inputmax_window_sum([1, 2, 3, 4, 5], 2)
Output9