Code Room
CodingEasycod-g1430
Subject Sliding windowLevel Entry–Mid~10 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Given an integer array nums and a window size k (1 <= k <= length of nums), return a list containing the sum of every window of k consecutive elements, from the leftmost window to the rightmost — n - k + 1 sums in total. Compute each subsequent sum from the previous one in O(1) rather than re-adding k elements. Example: nums = [1, 2, 3, 4], k = 2 gives [3, 5, 7].

Implement
window_sums(nums: list[int], k: int) → list[int]
Examples
in[[1,2,3,4],2]out[3,5,7]
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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.