Skip to content

Commit 7f566dd

Browse files
committed
Create README - LeetHub
1 parent 446d2fa commit 7f566dd

File tree

1 file changed

+48
-0
lines changed
  • 2125-number-of-laser-beams-in-a-bank

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<h2><a href="https://leetcode.com/problems/number-of-laser-beams-in-a-bank/">2125. Number of Laser Beams in a Bank</a></h2><h3>Medium</h3><hr><div><p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0'</code>s and <code>'1'</code>s. <code>'0'</code> means the cell is empty, while<code>'1'</code> means the cell has a security device.</p>
2+
3+
<p>There is <strong>one</strong> laser beam between any <strong>two</strong> security devices <strong>if both</strong> conditions are met:</p>
4+
5+
<ul>
6+
<li>The two devices are located on two <strong>different rows</strong>: <code>r<sub>1</sub></code> and <code>r<sub>2</sub></code>, where <code>r<sub>1</sub> &lt; r<sub>2</sub></code>.</li>
7+
<li>For <strong>each</strong> row <code>i</code> where <code>r<sub>1</sub> &lt; i &lt; r<sub>2</sub></code>, there are <strong>no security devices</strong> in the <code>i<sup>th</sup></code> row.</li>
8+
</ul>
9+
10+
<p>Laser beams are independent, i.e., one beam does not interfere nor join with another.</p>
11+
12+
<p>Return <em>the total number of laser beams in the bank</em>.</p>
13+
14+
<p>&nbsp;</p>
15+
<p><strong class="example">Example 1:</strong></p>
16+
<img alt="" src="https://assets.leetcode.com/uploads/2021/12/24/laser1.jpg" style="width: 400px; height: 368px;">
17+
<pre><strong>Input:</strong> bank = ["011001","000000","010100","001000"]
18+
<strong>Output:</strong> 8
19+
<strong>Explanation:</strong> Between each of the following device pairs, there is one beam. In total, there are 8 beams:
20+
* bank[0][1] -- bank[2][1]
21+
* bank[0][1] -- bank[2][3]
22+
* bank[0][2] -- bank[2][1]
23+
* bank[0][2] -- bank[2][3]
24+
* bank[0][5] -- bank[2][1]
25+
* bank[0][5] -- bank[2][3]
26+
* bank[2][1] -- bank[3][2]
27+
* bank[2][3] -- bank[3][2]
28+
Note that there is no beam between any device on the 0<sup>th</sup> row with any on the 3<sup>rd</sup> row.
29+
This is because the 2<sup>nd</sup> row contains security devices, which breaks the second condition.
30+
</pre>
31+
32+
<p><strong class="example">Example 2:</strong></p>
33+
<img alt="" src="https://assets.leetcode.com/uploads/2021/12/24/laser2.jpg" style="width: 244px; height: 325px;">
34+
<pre><strong>Input:</strong> bank = ["000","111","000"]
35+
<strong>Output:</strong> 0
36+
<strong>Explanation:</strong> There does not exist two devices located on two different rows.
37+
</pre>
38+
39+
<p>&nbsp;</p>
40+
<p><strong>Constraints:</strong></p>
41+
42+
<ul>
43+
<li><code>m == bank.length</code></li>
44+
<li><code>n == bank[i].length</code></li>
45+
<li><code>1 &lt;= m, n &lt;= 500</code></li>
46+
<li><code>bank[i][j]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
47+
</ul>
48+
</div>

0 commit comments

Comments
 (0)