← Back to challenges

Largest Numbers

PythonHardarraysnumbersconditionsalgorithms

Instructions

Create a function that takes two arguments of a list of numbers lst and a constant number n and returns the n largest numbers from the given list.

Examples

largest_numbers(2, [4, 3, 2, 1]) ➞ [3, 4]

largest_numbers(1, [7, 19, 4, 2]) ➞ [19]

largest_numbers(3, [14, 12, 57, 11, 18, 16]) ➞ [16, 18, 57]

largest_numbers(0, [1, 3, 4, 2]) ➞ []

Notes

The returned list must be sorted in ascending order.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Get Word Count