All problems

Quiz Leaderboard

Easy · sorting

After a maths quiz, every player has one result in the list results. Each result is a pair [player_id, score].

Put the results in leaderboard order and return them:

  1. A higher score comes first.
  2. If two players have the same score, the one with the smaller player id comes first.

Every player id appears only once. Return the full list of pairs in the new order.

Examples

Example 1

Input: results = [[7, 40], [3, 55], [9, 40], [1, 20]]

Output: [[3, 55], [7, 40], [9, 40], [1, 20]]

55 is the best score. Players 7 and 9 are tied on 40, so the smaller id (7) goes first.

Example 2

Input: results = [[2, 10], [1, 10]]

Output: [[1, 10], [2, 10]]

Equal scores, so the smaller id comes first.

Example 3

Input: results = [[5, 0]]

Output: [[5, 0]]

Constraints