28. Sliding Window Sum

You are given an array of integers and a window size k. Your task is to calculate the sum of each window of size k as it slides across the array from left to right.

Return all window sums in a single line, separated by space.


Example-1

Input: n = 5, k = 3,  arr = [1 2 3 4 5]
Output: 6 9 12


Example-2

Input: n = 4, k = 2 , arr = [10 20 30 40]
Output: 30 50 70

 

Loading...

Input

5 3 1 2 3 4 5

Expected Output

6 9 12