1729. Ranked Finishers
At the end of a programming contest, contestant names[i] solved solved[i] problems with a total time penalty of penalty[i]. The scoreboard ranks contestants by the number of problems solved, most first. Contestants with equal solved counts are ordered by smaller penalty first, and if the penalty also ties, by name in ascending lexicographic order.
All names are unique, so the final order is unique. Return the names as a string[] from the top rank down to the last. A comparator-based sort handles this in O(n log n) time and O(n) space.
Example 1
- Input:
- names = ["bo","amy","cy"]solved = [3,3,5]penalty = [100,90,400]
- Output:
- ["cy","amy","bo"]
- Explanation:
cy solved the most; amy and bo tie on 3 problems and amy has the lower penalty: ["cy", "amy", "bo"].
Example 2
- Input:
- names = ["zed","abe"], solved = [2,2], penalty = [50,50]
- Output:
- ["abe","zed"]
- Explanation:
Solved counts and penalties tie, so the names decide: ["abe", "zed"].
Example 3
- Input:
- names = ["solo"], solved = [0], penalty = [0]
- Output:
- ["solo"]
- Explanation:
One contestant is trivially ranked first: ["solo"].
Constraints
1 ≤ n ≤ 200
names are unique, each 1 to 10 lowercase letters
0 ≤ solved[i] ≤ 20
0 ≤ penalty[i] ≤ 105
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
- Time per case
- Python 4,000 msC++ 1,000 msJava 2,000 msJavaScript 2,000 msTypeScript 2,000 ms
Expected complexity
- Time
- O(n log n)
- Space
- O(n)