LeetCode solutions

1755. Defuse the Bomb

My accepted Python solution to LeetCode problem 1755, Defuse the Bomb, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.3MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.3MB, accepted 2025-12-29.

python
class Solution:
    def decrypt(self, code: List[int], k: int) -> List[int]:
        # Circular array sum with sliding window
        # Time: O(n), Space: O(n)
        n = len(code)
        result = [0] * n
        
        if k == 0:
            return result
        
        # Double the array for circular handling
        doubled = code + code
        
        if k > 0:
            # Sum next k elements
            for i in range(n):
                result[i] = sum(doubled[i+1:i+1+k])
        else:
            # Sum previous |k| elements
            k = -k
            for i in range(n):
                result[i] = sum(doubled[n+i-k:n+i])
        
        return result

Source