PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Roblox

Find maximum follow depth using recursion

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's competency with recursion, directed graph traversal, cycle detection, and memoization when computing longest-path depths in social-network-style follow graphs.

  • easy
  • Roblox
  • Coding & Algorithms
  • Data Scientist

Find maximum follow depth using recursion

Company: Roblox

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given a directed **follows** relationship representing a social graph: - Each record `(follower_id, followee_id)` means `follower_id` follows `followee_id`. - Treat this as a directed graph. ### Task Implement a function that, given: - a list of follow edges `follows = [(follower_id, followee_id), ...]` - a starting user `start_id` returns the **maximum number of follow “layers”** reachable from `start_id` by repeatedly following the next user. Formally, compute the length of the longest directed path starting at `start_id`: - Layer 1: users directly followed by `start_id` - Layer 2: users followed by those users - … Return the maximum layer count reachable. ### Requirements / edge cases - Use recursion (you may add memoization). - Handle cycles (e.g., A→B→C→A) without infinite recursion. - If `start_id` follows nobody, return `0`. ### Example If edges are: `1→2, 2→3, 3→4`, then `max_depth(1) = 3` (layers: {2}, {3}, {4}). If edges are: `1→2, 2→1`, then `max_depth(1) = 1` (cycle; do not loop forever).

Quick Answer: This question evaluates a candidate's competency with recursion, directed graph traversal, cycle detection, and memoization when computing longest-path depths in social-network-style follow graphs.

Related Interview Questions

  • Implement Sliding-Window Rate Limiter - Roblox (medium)
  • Find target-heavy sliding windows - Roblox (medium)
  • Find most frequent call path in logs - Roblox (medium)
  • Track Highest-Earning Experience - Roblox (medium)
  • Find the Most Frequent Log Call - Roblox (easy)
Roblox logo
Roblox
Dec 11, 2025, 12:00 AM
Data Scientist
Technical Screen
Coding & Algorithms
11
0

You are given a directed follows relationship representing a social graph:

  • Each record (follower_id, followee_id) means follower_id follows followee_id .
  • Treat this as a directed graph.

Task

Implement a function that, given:

  • a list of follow edges follows = [(follower_id, followee_id), ...]
  • a starting user start_id

returns the maximum number of follow “layers” reachable from start_id by repeatedly following the next user.

Formally, compute the length of the longest directed path starting at start_id:

  • Layer 1: users directly followed by start_id
  • Layer 2: users followed by those users
  • …

Return the maximum layer count reachable.

Requirements / edge cases

  • Use recursion (you may add memoization).
  • Handle cycles (e.g., A→B→C→A) without infinite recursion.
  • If start_id follows nobody, return 0 .

Example

If edges are: 1→2, 2→3, 3→4, then max_depth(1) = 3 (layers: {2}, {3}, {4}). If edges are: 1→2, 2→1, then max_depth(1) = 1 (cycle; do not loop forever).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Roblox•More Data Scientist•Roblox Data Scientist•Roblox Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.