Code RoomWindow sum skips first element
MediumPrep Room Coding #1907

Window sum skips first element

Code reviewAlgorithms & data structuresMid–Senior~16 min

Review this Python sliding-window sum that produces the sum of every contiguous window of size k.

Called in a metrics pipeline; `k` is user-configurable.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 16 min
Mark a line and say what kind of problem it is.0 findings
1def window_sums(a, k):
2 sums = []
3 s = sum(a[:k])
4 sums.append(s)
5 for i in range(k, len(a)):
6 s += a[i] - a[i - k]
7 sums.append(s)
8 return sums
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.