Description
You have a bomb to defuse. Your task is to replace code[i] with the sum of the next or previous k numbers depending on k value.
Examples
Input:
code = [5,7,1,4], k = 3Output:
[12,10,16,13]Explanation:
Sum of next 3 numbers for each.
Input:
code = [2,4,9,3], k = -2Output:
[12,5,6,13]Explanation:
With k=-2, each element is replaced by the sum of the previous 2 elements (wrapping circularly).
Input:
code = [1,2,3,4,5,6], k = 0Output:
[0,0,0,0,0,0]Explanation:
When k equals 0, each element is replaced with 0, regardless of the original array values. No numbers are summed since k=0 means no neighboring elements are considered.
Constraints
- •
n == code.length - •
1 ≤ n ≤ 100