File: defuse-the-bomb/solution.py

Date: 2026-06-06

Time: 16:13

defuse-the-bomb/solution.py

Purpose

This file solves LeetCode 1652 — Defuse the Bomb. It decrypts a circular array by replacing each element with the sum of its next or previous k neighbors, depending on the sign of k. It's a self-contained solution module following the repo's standard per-problem layout.

Key Components

Solution.minOperations(code, k) — Despite the method name (minOperations rather than the canonical decrypt), this implements the decryption logic. The contract:

Patterns

Dependencies

Flow

1. Compute n = len(code).

2. Short-circuit: if k == 0, return a zero-filled list immediately.

3. For each index i in [0, n):

4. Return result.

Python's % operator always returns a non-negative result for positive divisors, so (i - j) % n correctly wraps negative indices — no special handling needed.

Invariants

Error Handling

None. The function trusts its inputs match the LeetCode contract (non-empty list, |k| < n). No validation, no exceptions.

Notable Quirk

The method is named minOperations rather than the LeetCode-canonical decrypt. This is likely a copy-paste artifact from another problem's scaffold. It won't affect correctness (the test file presumably calls whatever method name is defined), but it would fail on LeetCode's judge as-is.