k
is zero, if so, return an array of zeros.code
array to handle the circular nature.res
with zeros.k
is positive, slide the window forward:
a. Initialize two pointers i
and j
and a sum variable.
b. Iterate through the array, updating the sum and result array as the window slides.k
is negative, slide the window backward:
a. Convert k
to a positive value for simplicity.
b. Initialize two pointers i
and j
from the end and a sum variable.
c. Iterate through the array in reverse, updating the sum and result array as the window slides.