Robinhood's referral program is pretty well known. The task is to build a dashboard to track the state of the referral program, specifically to understand how people refer others through a referral chain.
Assume a person refers everyone below them in the chain. For example, A refers B, C, and D in a referral chain A -> B -> C -> D. Build a leaderboard showing the top 3 users with the most referred users and their referral count.
Referral rules:
- A user can only be referred once.
- Once a user is already on the Robinhood platform, they cannot be referred by anyone else. For example: if A refers B, then no other user can refer A or B, because they are both already on the platform.
- The referrals in the input appear in the order they were created.
Leaderboard rules:
- A user must have at least 1 referral count to appear on the leaderboard.
- The leaderboard contains at most 3 users.
- The list should be sorted in descending order of referral count.
- If users have the same referral count, break the tie alphabetically by username.
Input:
rh_users -> a string array representing the usernames of the referrers
new_users -> a string array representing the usernames of the people being referred
rh_users = ["A", "B", "C"]
| | |
v v v
new_users = ["B", "C", "D"]
Output:
A string array of the top 3 users on the leaderboard. Each element is formatted as "[user] [referral count]". For example, "A 4".
Example:
Input:
rh_users = ["A", "B", "C"]
new_users = ["B", "C", "D"]
Output:
["A 3", "B 2", "C 1"]
Additional details:
- [execution time limit] 4 seconds
- [memory limit] 1GB
- [input] string array
rh_users, the usernames of the referrers. - [input] string array
new_users, the usernames of the referred users, in the same order as the corresponding entries inrh_users. - [output] string array, the top 3 users on the leaderboard. Each element formatted as
"[user] [referral count]". For example,"A 4".
Discussion
Loading comments…