Defuse the Bomb
Python solution:
|
|
In this code:
- We first initialize the result list
res
with zeros. Ifk
is zero, we return this list immediately. - If
k
is not zero, we prepare for the main computation by defining the initial window and sum. - If
k
is negative, we adjust the window to the end of the list. - We then compute the initial sum based on the current window.
- After that, we iterate over the list, updating the sum for the new window at each step, and storing this sum in the corresponding position in
res
. - The window is updated by removing the contribution of the old start, moving the start and end, and adding the contribution of the new end.
- Finally, we return
res
which contains the decrypted code.