← Moloco Interview Insights

Moloco·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Interviewed for a software engineer role at Molocoads and got a graph traversal problem about unlocking rooms. Pretty standard coding round, nothing too wild.

Questions Asked (1)

Q1

You have n rooms numbered 0 to n-1, all locked except room 0. Each room contains keys that can open other rooms. Given a list of keys per room, can you visit every room starting from room 0?

Algorithms & Data Structures
Author's notes

Classic reachability problem once you see it, but I stared at it for a moment before the graph framing clicked.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the rooms and keys as a directed graph where each room is a node and each key is a directed edge to another room. Use a graph traversal algorithm (DFS or BFS) starting from room 0, marking visited rooms, and at the end check if all rooms have been visited. This reduces the problem to checking reachability in a directed graph.

Pro tip: Clarify edge cases upfront, such as duplicate keys, keys to already visited rooms, or rooms with no keys, and mention that the solution runs in O(n + k) time where k is the total number of keys, which is optimal.

1. Understand the problem

Restate the problem: given n rooms and a list of keys per room, determine if all rooms can be visited starting from room 0. Confirm that keys are directed (a key in room i opens room j) and that rooms can be revisited.

2. Model as a graph

Represent each room as a node and each key as a directed edge from the room containing the key to the room it opens. This transforms the problem into checking if all nodes are reachable from node 0.

3. Choose traversal algorithm

Use DFS (recursive or iterative with a stack) or BFS (with a queue) to traverse the graph starting from room 0. Maintain a visited set to avoid cycles and redundant work.

4. Implement and verify

Write code to perform the traversal, marking rooms as visited when first encountered. After traversal, check if the number of visited rooms equals n; if yes, return true, else false.

5. Analyze complexity and edge cases

Discuss time complexity O(n + k) where k is total keys, and space O(n). Mention edge cases: n=1, empty key lists, duplicate keys, and keys to invalid rooms (if not guaranteed).

Key Points to Mention

  • Graph representation: rooms as nodes, keys as directed edges
  • DFS or BFS traversal from room 0
  • Visited set to avoid cycles and track reachable rooms
  • Time complexity O(n + k) and space O(n)
  • Edge cases: n=1, duplicate keys, keys to already visited rooms
  • Final check: visited count equals n

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.