Graph Theory37 sections · 1633 units
Open in Course

LeetCode 841 Keys and Rooms - Problem Statement

LeetCode 841

you apply DFS immediately. Problem: Keys and Rooms (LeetCode 841841). You start in room 00. Each room contains keys to other rooms. A key with number kk opens room kk. Can you visit every room?

This is a reachability problem. Model it as a directed graph where each room is a vertex and each key creates an edge. Run DFS from room 00. If you can reach all rooms, return true. Otherwise false. The graph is already given as an adjacency list (rooms array where rooms[i] contains keys in room i).