As reported: Robinhood round 1 coding interview (2025).
Users refer new users to the platform. A user is credited with everyone down their referral chain: if A → B → C → D (A referred B, B referred C, C referred D), then A has referred B, C and D (3 users), B has referred 2 and C has referred 1.
Referral rules
- A user can be referred only once.
- Once a user is on the platform — as a referrer or as a referred user — nobody can refer them. (If A refers B, no one can refer A or B afterwards.)
- Referrals are given in the order they were made.
Leaderboard rules
- Only users with at least 1 referral appear.
- At most 3 users.
- Sorted by referral count, descending; ties are broken by name in alphabetical order.
You are given two arrays of the same length: rhUsers[i] referred newUsers[i]. Return the leaderboard as strings "<name> <count>".
Example 1
rhUsers = ["A","B","C"]
newUsers = ["B","C","D"]
Output: ["A 3","B 2","C 1"]
Example 2
rhUsers = ["A","A","B"]
newUsers = ["B","C","D"]
Output: ["A 3","B 1"]
A referred B and C directly and D through B.
Constraints: 1 ≤ rhUsers.length = newUsers.length ≤ 10^5; names are non-empty strings of lowercase or uppercase English letters and digits; the referrals always follow the referral rules (and nobody refers themselves).
Code runner format: one JSON value per line: rhUsers, newUsers. Implement referralLeaderboard(rhUsers, newUsers); the harness prints the returned list.
Clarifications
- Alphabetical order compares names as plain strings, character by character.