Fixed Window Circular Sum

You are given a circular integer array code and an integer k. A circular array means the next element after the last element is the first element, and the previous element before the first element is the last element.

For each position i in the array, replace code[i] with the sum of the next k elements when k > 0, or the sum of the previous |k| elements when k < 0. When k = 0, replace code[i] with 0.

Return a new array of the same length containing the computed values.

Diagram

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 60" fill="none"> <text x="0" y="40" font-family="monospace" font-size="18" fill="currentColor">idx: 0→1→2→3→0→1→2→3→</text> <text x="0" y="58" font-family="monospace" font-size="18" fill="currentColor">arr: 5→2→3→1→5→2→3→1→</text> </svg>
Examples
Input: [1,2,3]
Output: [0,0,0]
Hints

Fixed Window Circular Sum

You are given a circular integer array `code` and an integer `k`. A circular array means the next element after the last element is the first element, and the previous element before the first element is the last element.