Practice Defuse the Bomb
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Replace every element of circular array code simultaneously, using only original values. If k is positive, use the sum of the next k elements. If k is negative, use the sum of the preceding -k elements. If k is zero, use 0. Wrap around the array at either end and return the transformed array.
Source: Defuse the Bomb on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
code = [5,7,1,4], k = 3
Output
[12,10,16,13]
# Example 2
Input
code = [1,2,3,4], k = 0
Output
[0,0,0,0]
# Example 3
Input
code = [2,4,9,3], k = -2
Output
[12,5,6,13]
Constraints
n == code.length
1 <= n <= 100
1 <= code[i] <= 100
-(n - 1) <= k <= n - 1
Related LeetCode Problems
Practice more problems similar to Defuse the Bomb.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.