Skip to the content

The top three scores

Problem

A game saves every score a person gets and wants to show their hall of fame.

Write a function that takes a list of scores and returns a list with the three highest, from largest to smallest.

If a score repeats, it takes a spot each time: with 40, 20, 40 and 30 the board is 40, 40 and 30.

If there are fewer than three scores, return the ones there are, also from largest to smallest. With an empty list you return an empty list.

Examples

  • Lots of scores

    [10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70] → [100, 90, 70]

  • Largest to smallest

    [20, 10, 30] → [30, 20, 10]

  • With a tie

    [40, 20, 40, 30] → [40, 40, 30]

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def top_three(scores):
    pass

JavaScript

function topThree(scores) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n log n) challenges

See all challenges →