All problems
0749EasyArrayHash TableStringSorting

Season Leaderboard From Two Parallel Lists

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2418Sort the People

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def leaderboard(names: list[str], scores: list[int]) -> list[str]:
Java
public String[] leaderboard(String[] names, int[] scores)
September 7
Apply