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) → contestId
  • joinContest(userId, contestId, team[]) → entryId
  • processMatchEvent(event) — e.g., "Virat Kohli scores 6 runs" → updates all affected teams' scores
  • getLeaderboard(contestId, page) → ranked list of teams
  • getUserRank(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 …
LeaderboardSalaryAccount