Tap here to switch tabs
Problem
Submissions

Problem: Defuse the Bomb

med
30 min
Try to solve the Defuse the Bomb problem.

Statement

You are given a circular array code of length n and an integer key k.

To decrypt the code, replace every element according to the value of k:

  • If k > 00, replace the iextthi^{ ext{th}} number with the sum of the next k numbers.

  • If k < 00, replace the iextthi^{ ext{th}} number with the sum of the previous ∣k∣|k| numbers.

  • If k == 00, replace the iextthi^{ ext{th}} number with 00.

As code is circular, the next element after code[n - 1] is code[0], and the element before code[0] is code[n - 1].

Return an array representing the decrypted code.

Constraints:

  • n ==== code.length

  • 1≤n≤1001 \leq n \leq 100

  • 1≤1 \leq code[i] ≤100\leq 100

  • −(n−1)≤-(n - 1) \leq k ≤n−1\leq n - 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Defuse the Bomb

med
30 min
Try to solve the Defuse the Bomb problem.

Statement

You are given a circular array code of length n and an integer key k.

To decrypt the code, replace every element according to the value of k:

  • If k > 00, replace the iextthi^{ ext{th}} number with the sum of the next k numbers.

  • If k < 00, replace the iextthi^{ ext{th}} number with the sum of the previous ∣k∣|k| numbers.

  • If k == 00, replace the iextthi^{ ext{th}} number with 00.

As code is circular, the next element after code[n - 1] is code[0], and the element before code[0] is code[n - 1].

Return an array representing the decrypted code.

Constraints:

  • n ==== code.length

  • 1≤n≤1001 \leq n \leq 100

  • 1≤1 \leq code[i] ≤100\leq 100

  • −(n−1)≤-(n - 1) \leq k ≤n−1\leq n - 1