Make Leaderboard
MediumP3Coding
names[i] scored marks[i] in a contest. Build the leaderboard:
- Sort by marks, highest first. Students with equal marks are ordered by name in ascending dictionary order.
- Students with equal marks share a rank. The next lower score gets the rank equal to its position in the list, so ranks skip (for example
1, 1, 3).
Return one string per student, formatted "<rank> <name>", in leaderboard order.
Example 1
- Input
- names = ["bob","amy","cal"], marks = [50,70,50]
- Output
- ["1 amy","2 bob","2 cal"]
- Why
- amy has the top score. bob and cal tie, ordered by name, both rank 2.
Example 2
- Input
- names = ["a","b","c"], marks = [9,9,5]
- Output
- ["1 a","1 b","3 c"]
Example 3
- Input
- names = ["z"], marks = [0]
- Output
- ["1 z"]
Constraints
- 1 <= names.length <= 10^4
- names.length == marks.length
- 0 <= marks[i] <= 10^9
- names are lowercase letters, length 1 to 20
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 9. ⌘Enter runs, ⌘⇧Enter submits.