Skip to content

Commit 3ec5716

Browse files
committed
Create README - LeetHub
1 parent f692ac6 commit 3ec5716

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Diff for: keys-and-rooms/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<h2>841. Keys and Rooms</h2><h3>Medium</h3><hr><div><p>There are <code>n</code> rooms labeled from <code>0</code> to <code>n - 1</code>&nbsp;and all the rooms are locked except for room <code>0</code>. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key.</p>
2+
3+
<p>When you visit a room, you may find a set of <strong>distinct keys</strong> in it. Each key has a number on it, denoting which room it unlocks, and you can take all of them with you to unlock the other rooms.</p>
4+
5+
<p>Given an array <code>rooms</code> where <code>rooms[i]</code> is the set of keys that you can obtain if you visited room <code>i</code>, return <code>true</code> <em>if you can visit <strong>all</strong> the rooms, or</em> <code>false</code> <em>otherwise</em>.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong>Example 1:</strong></p>
9+
10+
<pre><strong>Input:</strong> rooms = [[1],[2],[3],[]]
11+
<strong>Output:</strong> true
12+
<strong>Explanation:</strong>
13+
We visit room 0 and pick up key 1.
14+
We then visit room 1 and pick up key 2.
15+
We then visit room 2 and pick up key 3.
16+
We then visit room 3.
17+
Since we were able to visit every room, we return true.
18+
</pre>
19+
20+
<p><strong>Example 2:</strong></p>
21+
22+
<pre><strong>Input:</strong> rooms = [[1,3],[3,0,1],[2],[0]]
23+
<strong>Output:</strong> false
24+
<strong>Explanation:</strong> We can not enter room number 2 since the only key that unlocks it is in that room.
25+
</pre>
26+
27+
<p>&nbsp;</p>
28+
<p><strong>Constraints:</strong></p>
29+
30+
<ul>
31+
<li><code>n == rooms.length</code></li>
32+
<li><code>2 &lt;= n &lt;= 1000</code></li>
33+
<li><code>0 &lt;= rooms[i].length &lt;= 1000</code></li>
34+
<li><code>1 &lt;= sum(rooms[i].length) &lt;= 3000</code></li>
35+
<li><code>0 &lt;= rooms[i][j] &lt; n</code></li>
36+
<li>All the values of <code>rooms[i]</code> are <strong>unique</strong>.</li>
37+
</ul>
38+
</div>

0 commit comments

Comments
 (0)