48. Keys and Rooms

There are n rooms in a building (from 0 to n-1). Room i contains keys rooms[i]. Initially only room 0 is unlocked. Can you visit all the rooms?
Example 1
Input: rooms = [[1,3],[3,0,1],[2],[0]]
Output: False
Explanation: There are no keys to room 2 from reachable rooms, so you cannot visit them all.
Example 2
Input: rooms = [[1],[2],[3],[]]
Output: True
Explanation: From room 0, you can reach every room by following the chain of keys.
arraysgraphmediumqueue
JavaScript
Loading...
Line 1, Char 1