Build an in-memory leaderboard for a fantasy-sports style app. Each user creates exactly one team made up of one or more players. As a live match progresses, players receive positive or negative points. A user’s score is the sum of the current scores of all players on that user’s team. You must support querying the Top-K users ranked by score.
0 (before any player points are applied).userId in lexicographically ascending order.void addUser(String userId, List<String> playerIds)userId will always be globally unique and non-blank.playerIds will contain at least one element; each playerId is non-blank and valid.0.void addScore(String playerId, int score)score is an integer in the inclusive range [-1000, 1000].playerId must have their team scores updated accordingly.List<String> getTopK(int k)k >= 1. If k exceeds the total number of users, return all users.userId values sorted by:
userId lexicographically ascending to break ties.
// Sequence (illustrative):
addUser("uA", ["p1", "p2"])
addUser("uB", ["p2"])
getTopK(2) // ["uA", "uB"] // both 0; "uA" < "uB"
addScore("p2", 10) // p2 = 10; uA=10 (p1=0 + p2=10), uB=10
getTopK(2) // ["uA", "uB"] // tie by score, lex by userId
addScore("p1", 3) // p1 = 3; uA=13, uB=10
getTopK(1) // ["uA"]
addScore("p2", -5) // p2 = 5; uA=8 (3+5), uB=5
getTopK(5) // return all users: ["uA", "uB"]