PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Robinhood

Count Referral Descendants

Last updated: May 5, 2026

Quick Overview

This question evaluates graph and tree reasoning, algorithmic aggregation for computing descendant counts, and system-level thinking for incremental updates and recursion-depth mitigation.

  • medium
  • Robinhood
  • Coding & Algorithms
  • Software Engineer

Count Referral Descendants

Company: Robinhood

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are building a referral analytics feature. Each referral relationship is represented as a directed pair `(referrer, referredUser)`, meaning `referrer` directly invited `referredUser`. A user may directly refer many users, but each user has at most one direct referrer. Assume the referral graph is acyclic, so it forms one or more rooted trees. Given a list of referral pairs, compute for every user the total number of users in their referral network, including both direct and indirect referrals. In other words, for each user, return the number of descendants reachable from that user. Example: ```text referrals = [ ("A", "B"), ("A", "C"), ("B", "D"), ("B", "E"), ("C", "F") ] ``` Expected result: ```text A -> 5 B -> 2 C -> 1 D -> 0 E -> 0 F -> 0 ``` Requirements: 1. Return a mapping from every user appearing in the input to their total referral count. 2. Explain the time and space complexity. 3. Discuss how you would find the top 3 users by referral count efficiently. 4. Discuss how you would avoid recursion-depth issues for very deep referral chains. 5. Follow-up: suppose this is an online production system where referral relationships are continuously added. The graph is very large, and recomputing all counts after every insertion is too expensive. Design an approach to support incremental updates when a new referral edge is added.

Quick Answer: This question evaluates graph and tree reasoning, algorithmic aggregation for computing descendant counts, and system-level thinking for incremental updates and recursion-depth mitigation.

Related Interview Questions

  • Build a Weekly Calendar - Robinhood (medium)
  • Solve path and inventory problems - Robinhood
  • Implement Calendar Layout and String Packing - Robinhood (medium)
  • Aggregate user logs into 30-minute sessions - Robinhood (hard)
  • Compute dependency load factors in a DAG - Robinhood (medium)
Robinhood logo
Robinhood
Feb 26, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0

You are building a referral analytics feature.

Each referral relationship is represented as a directed pair (referrer, referredUser), meaning referrer directly invited referredUser. A user may directly refer many users, but each user has at most one direct referrer. Assume the referral graph is acyclic, so it forms one or more rooted trees.

Given a list of referral pairs, compute for every user the total number of users in their referral network, including both direct and indirect referrals. In other words, for each user, return the number of descendants reachable from that user.

Example:

referrals = [
  ("A", "B"),
  ("A", "C"),
  ("B", "D"),
  ("B", "E"),
  ("C", "F")
]

Expected result:

A -> 5
B -> 2
C -> 1
D -> 0
E -> 0
F -> 0

Requirements:

  1. Return a mapping from every user appearing in the input to their total referral count.
  2. Explain the time and space complexity.
  3. Discuss how you would find the top 3 users by referral count efficiently.
  4. Discuss how you would avoid recursion-depth issues for very deep referral chains.
  5. Follow-up: suppose this is an online production system where referral relationships are continuously added. The graph is very large, and recomputing all counts after every insertion is too expensive. Design an approach to support incremental updates when a new referral edge is added.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Robinhood•More Software Engineer•Robinhood Software Engineer•Robinhood Coding & Algorithms•Software Engineer 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.