Season standings
MediumOnline Assessment
Compute the final standings of a season-long points league.
Each result is a string "player:contest:score". The score is a non-negative integer, or the text DQ when the player was disqualified in that contest. Players can appear many times, including several times in the same contest (reruns).
Rules:
- Player names are case-insensitive after trimming spaces at both ends (
"Ann "and"ann"are the same player); they are reported in lowercase. Contest ids are compared exactly. - For one player in one contest: if any of their entries for that contest is
DQ, the contest is voided and scores 0 for that player, whatever their other entries say. Otherwise the contest scores the highest of their entries. - A player's total is the sum of their
besthighest contest scores (a voided contest counts as a contest scoring 0). If the player has fewer thanbestcontests, all of them are summed. - Every player with at least one entry appears in the standings, even with a total of 0.
- Players are ordered by total descending, and by name ascending (lexicographic) when totals are equal. Ranks use standard competition ranking: players with equal totals share a rank, and the next rank skips the positions used (totals 90, 80, 80, 70 get ranks 1, 2, 2, 4).
Input: results, a list of strings in the format above, and best, a positive integer.
Output: a list of [rank, name, total] rows in standings order. If results is empty, return [].
Example 1
- Input:
- [["Ann:c1:50","bob:c1:70","ANN:c2:30","bob:c2:10"],2]
- Output:
- [[1,"ann",80],[1,"bob",80]]
- Explanation
- Names are case-insensitive, so "Ann" and "ANN" are one player. ann scores 50 + 30 = 80 and bob 70 + 10 = 80. Both are tied for first and share rank 1, listed by name.
Example 2
- Input:
- [["ann:c1:50","ann:c1:90","ann:c1:DQ","bo:c1:20","bo:c2:35","cy:c2:35","cy:c3:5"],1]
- Output:
- [[1,"bo",35],[1,"cy",35],[3,"ann",0]]
- Explanation
- Entries for ann in c1 are 50, 90 and DQ. The DQ voids the whole contest for her, so it scores 0 and her total is 0. Only the best 1 contest counts: bo gets 35 (contest c2) and cy gets 35, tied at rank 1. ann is third in the list, so her rank is 3, and she still appears because she entered.
Example 3
- Input:
- [["a:x:10","a:y:20","a:y:25","a:z:5","b:x:25","c:x:25"," d:x:DQ"],2]
- Output:
- [[1,"a",35],[2,"b",25],[2,"c",25],[4,"d",0]]
- Explanation
- Only the best 2 contests count. a's contest scores are x 10, y 25 (the better of 20 and 25) and z 5, so a gets 25 + 10 = 35. b and c have 25 and tie at rank 2. d was disqualified in the only contest, total 0, listed fourth: after a tie at rank 2 the next rank is 4, not 3.
Constraints
0 <= results.length <= 1,0001 <= best <= 20- Each entry is
"player:contest:score"whereplayerhas ASCII letters and spaces,contestis a non-empty string of letters and digits, andscoreis an integer from0to1,000or the textDQ