Loading...
Loading...
Loading...
A shop records the number of orders each hour. After each hour, report the total orders of the last k hours, or of all the hours so far if fewer than k have passed.
Example 1
Input
5 3 4 6 8 2 10
Output
4 10 18 16 20
The totals are 4, 10, 18, 16 and 20.
Example 2
Input
3 1 5 6 7
Output
5 6 7
Try the problem first. Open one hint at a time.
A deque with maxlen=k forgets the oldest hour by itself.
Keep a running total. Subtract the oldest value just before it leaves.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor