Implement a referral network system (similar to a social network follower/followee graph) in three parts:
Part 1: Design and implement the core referral network data structure. Each user can be a referrer (who recommends others) and/or a referee (who was recommended). Support operations such as adding referral relationships.
Part 2: Built on Part 1, implement two ranking functions that return the top-K users by:
Part 3: Implement a function to estimate the expected total network size after N days, given: every referrer has probability p of making one successful referral each day, and each person can make at most 10 successful referrals over their lifetime.
No test cases are provided; candidates must write and run their own tests. LLMs are not allowed for Parts 1 & 2 (Google for syntax only); Part 3 is done live with the interviewer.
Walk me through your data structure choice and how you handle cycles or duplicate referrals.
How does your flow centrality calculation work, and what is its time complexity?
How does the 10-referral lifetime cap affect your model, and how did you account for it?
| Approach | Notes |
|---|---|
| Memoized DFS for descendant count | Caches subtree sizes to avoid recomputation across multiple top-K queries, but requires cache invalidation if the graph is mutable. |
| Monte Carlo simulation for Part 3 | Easier to implement and handles complex stochastic dependencies, but is approximate and slower than closed-form expected value computation. |
Common mistakes: No test cases are provided; candidates must write and run their own tests. Failing to self-test likely hurt results.
Interviewer hints: The interviewer joins after the first 60 minutes of async coding to review Parts 1 and 2 before the candidate completes Part 3 live.; Google search is allowed but only for syntax lookups, not for algorithmic approaches like graph traversal strategies.