Design A Leaderboard
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Implement Leaderboard for a game that tracks players' running scores.
- addScore(playerId, score) adds score to the player's total. A player who is not on the board joins with that score.
- top(K) returns the sum of the K highest totals currently on the board.
- reset(playerId) removes the player from the board (their total goes back to zero). It is only called for players who are on the board.
top(K) is only called when at least K players are on the board. A reset player who scores again rejoins as a new entry.
Examples
Constraints
- 1 <= playerId, K <= 10^4
- 1 <= score <= 100
- `K` is at most the number of players on the board
- At most 1000 calls in total
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.