Design a Real-Time Fantasy Contest Leaderboard
Problem
Design the OOP model for a real-time fantasy cricket contest leaderboard that updates as match events occur.
Requirements
createContest(matchId, entryFee, prizePool)→ contestIdjoinContest(userId, contestId, team[])→ entryIdprocessMatchEvent(event)— e.g., "Virat Kohli scores 6 runs" → updates all affected teams' scoresgetLeaderboard(contestId, page)→ ranked list of teamsgetUserRank(contestId, userId)→ current rank and score
Key classes
Contest, Team, Player, MatchEvent, ScoringEngine, Leaderboard
Performance challenge
A single match event may affect millions of teams. How do you update scores without iterating every team?
Hint
Invert the index: playerIdToTeamIds map allows O(teams_with_player) update per event.
added …