Skip to content

Commit c7b4241

Browse files
committed
Create README - LeetHub
1 parent 4a417a4 commit c7b4241

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

1652-defuse-the-bomb/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<h2><a href="https://leetcode.com/problems/defuse-the-bomb/">1652. Defuse the Bomb</a></h2><h3>Easy</h3><hr><div><p>You have a bomb to defuse, and your time is running out! Your informer will provide you with a <strong>circular</strong> array <code>code</code>&nbsp;of length of <code>n</code>&nbsp;and a key <code>k</code>.</p>
2+
3+
<p>To decrypt the code, you must replace every number. All the numbers are replaced <strong>simultaneously</strong>.</p>
4+
5+
<ul>
6+
<li>If <code>k &gt; 0</code>, replace the <code>i<sup>th</sup></code> number with the sum of the <strong>next</strong> <code>k</code> numbers.</li>
7+
<li>If <code>k &lt; 0</code>, replace the <code>i<sup>th</sup></code> number with the sum of the <strong>previous</strong> <code>k</code> numbers.</li>
8+
<li>If <code>k == 0</code>, replace the <code>i<sup>th</sup></code> number with <code>0</code>.</li>
9+
</ul>
10+
11+
<p>As <code>code</code> is circular, the next element of <code>code[n-1]</code> is <code>code[0]</code>, and the previous element of <code>code[0]</code> is <code>code[n-1]</code>.</p>
12+
13+
<p>Given the <strong>circular</strong> array <code>code</code> and an integer key <code>k</code>, return <em>the decrypted code to defuse the bomb</em>!</p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong class="example">Example 1:</strong></p>
17+
18+
<pre><strong>Input:</strong> code = [5,7,1,4], k = 3
19+
<strong>Output:</strong> [12,10,16,13]
20+
<strong>Explanation:</strong> Each number is replaced by the sum of the next 3 numbers. The decrypted code is [7+1+4, 1+4+5, 4+5+7, 5+7+1]. Notice that the numbers wrap around.
21+
</pre>
22+
23+
<p><strong class="example">Example 2:</strong></p>
24+
25+
<pre><strong>Input:</strong> code = [1,2,3,4], k = 0
26+
<strong>Output:</strong> [0,0,0,0]
27+
<strong>Explanation:</strong> When k is zero, the numbers are replaced by 0.
28+
</pre>
29+
30+
<p><strong class="example">Example 3:</strong></p>
31+
32+
<pre><strong>Input:</strong> code = [2,4,9,3], k = -2
33+
<strong>Output:</strong> [12,5,6,13]
34+
<strong>Explanation:</strong> The decrypted code is [3+9, 2+3, 4+2, 9+4]. Notice that the numbers wrap around again. If k is negative, the sum is of the <strong>previous</strong> numbers.
35+
</pre>
36+
37+
<p>&nbsp;</p>
38+
<p><strong>Constraints:</strong></p>
39+
40+
<ul>
41+
<li><code>n == code.length</code></li>
42+
<li><code>1 &lt;= n&nbsp;&lt;= 100</code></li>
43+
<li><code>1 &lt;= code[i] &lt;= 100</code></li>
44+
<li><code>-(n - 1) &lt;= k &lt;= n - 1</code></li>
45+
</ul>
46+
</div>

0 commit comments

Comments
 (0)