Code RoomSliding window sums
EasyPrep Room Coding #490

Sliding window sums

CodingAlgorithms & data structuresEntry–Mid~12 min

Given a list of integers and a window width w (w >= 1), return the sums of every contiguous window of exactly w elements, left to right. The result has length n - w + 1 for a list of length n; if w exceeds n, return an empty list. Values may be negative. Example: values = [1, 3, 2, 6], w = 2 gives [4, 5, 8].

Implement
window_totals(values: list[int], w: int) → list[int]
Examples
in[[1,3,2,6],2]out[4,5,8]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 12 min
InputExpectedGot
[[1,3,2,6],2][4,5,8]not run yetsample