← 返回 meta 的题目列表Design a Leaderboard
类型:online_judge
meta
Design a leaderboard feature for a website or application. The functionality should include recording the score for a specific user, returning the top K users, and resetting the score for a particular user. Implement a class with the following methods:
addScore(userId: int, score: int) -> void: Updates the score for a specific user.
top(K: int) -> List[int]: Returns the IDs of the top K users on the leaderboard.
reset(userId: int) -> void: Resets the score of a specific user to zero.
Detail the time and space complexity for each method, and use appropriate data structures if necessary.
Example
Input
addScore(1, 50)
addScore(2, 30)
addScore(3, 40)
top(2)
reset(1)
top(2)