Sort the People
Real-world version: Season Leaderboard From Two Parallel ListsThe statement here is our own: the same inputs, outputs and technique.
A club keeps its season results in two lists of the same length. names[i] is the name a competitor entered under and scores[i] is the number of points that same competitor finished on, so position i of one list always refers to the same competitor as position i of the other.
Every score in scores is different from every other, so the ranking never needs a tie-break. Two competitors may still have entered under the same name.
Return the names arranged from the highest score down to the lowest.
Examples
Example 1
- Input
- names = ["Rhea", "Tomas", "Ines"], scores = [9, 100, 25]
- Output
- ["Tomas", "Ines", "Rhea"]
Tomas finished on 100, Ines on 25 and Rhea on 9, so that is the order from highest score to lowest.
Example 2
- Input
- names = ["zeta", "Alpha"], scores = [7, 12]
- Output
- ["Alpha", "zeta"]
Alpha's 12 beats zeta's 7, so Alpha comes first. The names themselves play no part in the order.
Example 3
- Input
- names = ["Wu", "Baz", "Kim", "Ana"], scores = [3, 47, 12, 1]
- Output
- ["Baz", "Kim", "Wu", "Ana"]
The scores from highest to lowest are 47, 12, 3 and 1, which belong to Baz, Kim, Wu and Ana in that order.
Constraints
- names.length == scores.length
- 1 <= names.length <= 10^3
- 1 <= names[i].length <= 20
- 1 <= scores[i] <= 10^5
- names[i] consists of lowercase and uppercase English letters only.
- All the values in scores are different from one another.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def leaderboard(names: list[str], scores: list[int]) -> list[str]:public String[] leaderboard(String[] names, int[] scores)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 13 test cases: 13 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's