← Roblox Interview Insights

Roblox·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Roblox data scientist interview had a graph traversal coding question that was more algorithmic than I expected for a DS role. One question, but it had enough edge cases to keep me busy for a while.

Questions Asked (1)

Q1

Given a directed social graph as a list of follower/followee pairs and a starting user, write a recursive function that returns the maximum number of 'follow layers' reachable from that user. Must handle cycles without infinite recursion.

Algorithms & Data Structures
Author's notes

The cycle handling is what tripped me up first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the graph representation and define 'follow layers' as the maximum depth of the reachable subgraph. Use DFS with a visited set to avoid cycles, and compute the maximum depth recursively by exploring each neighbor and taking the maximum depth plus one. Discuss trade-offs between recursion depth and iterative BFS if the graph is large.

Pro tip: Mention that in production systems like Roblox, recursion depth can be a limitation, so an iterative BFS with level tracking is often preferred; also highlight the importance of handling disconnected components and self-loops.

1. Clarify the problem

Ask clarifying questions about the graph representation (adjacency list vs. edge list), whether the starting user is included in the layer count, and how to handle cycles (e.g., visited set).

2. Define the recursive function

Define a function that takes a node and a visited set, returns the maximum depth from that node. For each unvisited neighbor, recursively compute depth and track the maximum.

3. Handle cycles and base cases

Mark the current node as visited before recursing. If a node has no unvisited neighbors, return 0 (or 1 if counting the node itself). Ensure visited set is shared across recursion to avoid infinite loops.

4. Analyze complexity and edge cases

Discuss time and space complexity (O(V+E) time, O(V) space for visited set and recursion stack). Mention edge cases: empty graph, start node not in graph, self-loops, and very deep graphs causing stack overflow.

5. Propose optimizations or alternatives

Suggest iterative BFS with level tracking to avoid recursion limits, or memoization if the graph is a DAG. Mention that for very large graphs, distributed processing might be needed.

Key Points to Mention

  • Use a visited set to prevent infinite recursion in cycles.
  • Define 'follow layers' as the maximum depth of the reachable subgraph from the start node.
  • Recursive DFS with depth tracking: max_depth = max(1 + dfs(neighbor) for each unvisited neighbor).
  • Time complexity O(V+E) and space complexity O(V) for visited set and recursion stack.
  • Edge cases: self-loops, disconnected components, start node with no followers, and stack overflow for deep graphs.
  • Alternative: iterative BFS with level order traversal to avoid recursion depth limits.

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