FunctionRacerProblemsRace

Leaderboard With Shared Ranks

EasyClassesPython, JavaScript, TypeScript, Java, C++

Implement a class Leaderboard that keeps each player's best score and ranks the players, with equal scores sharing a rank. Write these methods:

The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

Leaderboard()
submit("ana", 50) returns 50
submit("ben", 70) returns 70
submit("cal", 50) returns 50
submit("ana", 40) returns 50
rank_of("ben") returns 1
rank_of("ana") returns 2
rank_of("cal") returns 2
top_players(2) returns ["ben","ana"]
rank_of("dan") returns -1

ana keeps her best score 50 after submitting 40. Only ben is higher, so ana and cal share rank 2. The top two are ben, then ana, who comes before cal alphabetically. dan never played.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems