There are n rooms labeled 0 to n - 1. Every room except room 0 starts locked. Room i holds a set of keys, rooms[i], and each key opens the room with that number. You start in room 0, and whenever you enter a room you can take all of its keys. Return true if you can visit every room, otherwise false.
There are n rooms labeled 0 to n - 1. Every room except room 0 starts locked. Room i holds a set of keys, rooms[i], and each key opens the room with that number. You start in room 0, and whenever you enter a room you can take all of its keys. Return true if you can visit every room, otherwise false.
Example 1:
Input: {"rooms":[[1],[2],[3],[]]}
Output: true
Constraints:
n==rooms.length
2≤n≤1000
0≤rooms[i].length≤1000
1≤∑rooms[i].length≤3000
0≤rooms[i][j]<n
All the values of rooms[i] are unique.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"rooms":[[1],[2],[3],[]]}
4 rooms. Only room 0 is open; every other door needs its key.