0 day streak
Anonymous · shared experience20 Jun 2025 · 10 views

Robinhood: Top-three referral leaderboard counting indirect referrals

Interview question #Robinhood DSA / coding

Problem. Two parallel arrays describe referrals in the order they happened: rh_users[i] referred new_users[i]. A user gets credit for everyone below them in their referral chain, not only the people they referred directly. Return a leaderboard of at most three users, formatted as "user count".

Example. With referrers [A, B, C] and new users [B, C, D], the chain is A -> B -> C -> D, so the output is ["A 3", "B 2", "C 1"].

Rules

  • Each user can be referred only once, and someone already on the platform cannot be referred again or refer an existing user.
  • Only users with at least one referral appear.
  • Sort by count descending; break ties alphabetically by name.

Constraints given. A 4-second time limit and generous memory; starter code returned placeholder output.

What to focus on. Correct transitive counting (each new user adds one to every ancestor up the chain), honoring the referral rules, and exact sort and tie-break output. Think about how the cost grows when chains get long.

0 comments

Comments 0

No comments yet. Ask the author something, or add what happened in your own round.