2025-08-10 09:45:06 +0000 UTC

Defuse the Bomb

Code

class Solution:
    def decrypt(self, code: List[int], k: int) -> List[int]:
        length = len(code)
        result = [0 for _ in range(length)]
        if k == 0:
            return result
        start, end, window_sum = 1, k + 1, 0
        if k < 0:
            start = length - (-k)
            end = length
        for i in range(start, end):
            window_sum += code[i]
        for i in range(length):
            result[i] = window_sum
            window_sum -= code[start % length]
            window_sum += code[end % length]
            start += 1
            end += 1
        return result