Problem · Graph

Keys and Rooms

Learn this problem
MediumAtlassian logoAtlassianFULLTIMEOA

Problem statement

Room zero is initially unlocked. Each room contains keys to other rooms. Return whether all rooms can be visited.

Function

canVisitAllRooms(rooms: int[][]) → boolean

Examples

Example 1

rooms = [[1],[2],[3],[]]return = true

Keys discovered in order unlock rooms 1, 2, and 3.

Constraints

  • 1 <= rooms.length <= 10000
  • Every key is a valid room index.

More Atlassian problems

drafts saved locally
public boolean canVisitAllRooms(int[][] rooms) {
  // Write your code here.
}
rooms[[1],[2],[3],[]]
expectedtrue
checking account