Skip to content
DeepForgeby svx
All problems
EasyData Structuresds-306

Tumbling Window Aggregate

Problem

Aggregate a stream into tumbling windows.

sizes is the sequence of values and window is the number of items per window; the final window may be partial.

Return the list of window sums.

Hint

Windows never overlap, so slice the input in strides.

Test cases

case 1
in: [[1,2,3,4,5],2]
expected: [3,7,5]
case 2
in: [[],2]
expected: []
case 3
in: [[1],3]
expected: [1]
case 4
in: [[1,2,3,4],4]
expected: [10]
Starter codePython
def tumbling_window(sizes, window):
    # Your code here
    pass

4 test cases · run your code against them in the editor