you apply DFS immediately. Problem: Keys and Rooms (LeetCode ). You start in room . Each room contains keys to other rooms. A key with number opens room . 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 . 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).