Sliding Window Sum
Problem Description
Given an array of signal samples arr_in and a window size K, compute the sum of every contiguous window of size K as it slides across the array.
If K is larger than the array , return an empty array instead of crashing or accessing out-of-bounds elements.
Examples
Example 1
Input: arr_in = [10, 20, 30, 40, 50], k = 3
Output: [60, 90, 120]
Explanation: sum(10,20,30)=60, sum(20,30,40)=90, sum(30,40,50)=120
Example 2
Input: arr_in = [10, 20, 30, 40, 50], k = 10
Output: []
Explanation: k exceeds array size, no valid window exists
Example 3
Input: arr_in = [], k = 1
Output: []
Explanation: empty input array
SystemVerilog
Code Editor Access
Log in to write, run and submit your solution to this interview question. It's free.
