Tap here to switch tabs
Problem
Submissions

Problem: Keys and Rooms

med
30 min
Try to solve the Keys and Rooms problem.

Statement

You are given n rooms labeled from 00 to n1n - 1 as a list rooms, where rooms[i] contains the keys available inside room i. Each key is an integer representing the label of a room it can unlock.

You start in room 00, and you can collect keys from any room you are able to enter. A room can be entered if you already have its key, except for room 00 which is initially open.

Return true if it is possible to enter every room, otherwise return false.

Constraints:

  • n == rooms.length

  • 22 \leq n 1000\leq 1000

  • 00 \leq rooms[i].length 1000\leq 1000

  • 11 \leq \sum(rooms[i].length) 3000\leq 3000

  • 00 \leq rooms[i][j] << n

  • All values in rooms[i] are unique

Tap here to switch tabs
Problem
Submissions

Problem: Keys and Rooms

med
30 min
Try to solve the Keys and Rooms problem.

Statement

You are given n rooms labeled from 00 to n1n - 1 as a list rooms, where rooms[i] contains the keys available inside room i. Each key is an integer representing the label of a room it can unlock.

You start in room 00, and you can collect keys from any room you are able to enter. A room can be entered if you already have its key, except for room 00 which is initially open.

Return true if it is possible to enter every room, otherwise return false.

Constraints:

  • n == rooms.length

  • 22 \leq n 1000\leq 1000

  • 00 \leq rooms[i].length 1000\leq 1000

  • 11 \leq \sum(rooms[i].length) 3000\leq 3000

  • 00 \leq rooms[i][j] << n

  • All values in rooms[i] are unique