Problem 43 of 75

Keys and Rooms

MediumNot solved yetInterview me on this
Before you code · which pattern fits?

The problem

There are n rooms labeled 0..n-1; all rooms are locked except room 0. rooms[i] is the list of keys found in room i. Return true if you can visit all the rooms.

[[1],[2],[3],[]] → true [[1,3],[3,0,1],[2],[0]] → false

Your solution runs against 2 unit tests, including edge and large-value cases.

Loading...

Test console · 2 unit tests

Submit your code to run it against all 2 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.

Hint

Reference solution

Video explanation

Keys and Rooms, explainedNick White