Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Keys and Rooms

XPChallenge Points: 20
levelLevel: Medium

There are n rooms labeled from 0 to n - 1, and all rooms are locked except for room 0.
Your goal is to visit all the rooms.
• You can only enter a locked room if you have its key.
• When you enter a room, you may find one or more keys that unlock other rooms.
• You can carry all the keys you find to use later.
Return True if you can visit every room, otherwise False.

Example 1:

Input: rooms = [[1],[2],[3],[]]

Output: True

Example 2:

Input: rooms = [[1,3],[3,0,1],[2],[0]]

Output: False

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result