Keys and Rooms
A medium-tier problem at 75% community acceptance, tagged with Depth-First Search, Breadth-First Search, Graph. Reported in interviews at Graviton and 4 others.
You're in a castle with n rooms. Each room has a list of keys to other rooms. Start in room 0, unlock what you can reach, figure out if you can visit every room. It's asked at Graviton, Nvidia, Expedia, Walmart Labs, and Tinkoff. The trap is thinking you need to simulate a physical traversal. You don't. This is a graph reachability problem disguised as a puzzle, and the 74% acceptance rate is misleading because the moment you see the pattern, it's trivial. If you blank on the trick during your assessment, StealthCoder solves it in seconds while remaining invisible to the proctor.
Companies that ask "Keys and Rooms"
Keys and Rooms is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe algorithm is simple once you recognize it: treat each room as a node and each key as a directed edge. Run DFS or BFS from room 0, marking every room you can reach. Count reachable rooms against the total. The pitfall is overcomplicating it. Candidates often try to track key sequences or simulate a physical state machine when the problem just wants reachability. BFS is slightly more intuitive here because you pop a room, grab its keys, and queue the unlocked rooms. DFS works identically. The real trick is recognizing that visited rooms prevent cycles, so you won't loop forever. Most of the time candidates code it correctly but second-guess the logic. If this hits your live OA and you hesitate on whether to use graph traversal or simulation, StealthCoder surfaces the clean BFS or DFS solution immediately, cutting through the doubt.
Pattern tags
You know the problem.
Make sure you actually pass it.
Keys and Rooms recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Keys and Rooms interview FAQ
Is Keys and Rooms actually easy or are the acceptance rates wrong?+
The 74% acceptance rate is legit. Once you recognize it's a graph reachability problem, the code is 10 lines. The confusion comes from the puzzle framing. Candidates overthink the state transitions or think they need to track key chains. The moment you see DFS or BFS, it clicks. It's a gatekeeping problem, not a hard problem.
Do I use DFS or BFS for this problem?+
Either works identically. BFS is slightly more natural here because you dequeue a room, iterate its keys, and enqueue new rooms. DFS is equally valid and marginally shorter code. Pick whichever you're more comfortable coding under pressure. Both are O(n plus m) where n is rooms and m is total keys.
What's the common mistake candidates make?+
Overthinking state. Candidates try to track which keys they're holding, or simulate unlocking in sequence, or worry about revisiting rooms. You don't care about key order or sequences. Just mark visited rooms and explore. If you've seen a room, skip it. That's it.
Does Nvidia or Expedia ask this problem differently than smaller companies?+
No. The problem statement is standard across all five companies that ask it. Graviton, Tinkoff, Expedia, Walmart Labs, and Nvidia all expect the same graph traversal solution. No variant quirks reported.
How should I prepare for this if it shows up in my OA?+
Drill DFS and BFS once on a simple graph problem first. Then code Keys and Rooms from scratch three times. The third time you'll notice you're writing it on autopilot. That's the goal. If you blank during the real assessment, StealthCoder runs invisibly and gives you a working solution in under a minute.
Want the actual problem statement? View "Keys and Rooms" on LeetCode →