The largest in the list
- O(n) · Medium
- Full plan
- Python
- JavaScript
- lists
- loops
Problem
Write a function that takes a list of numbers and returns the largest one. Walk through the list and keep the biggest one you have seen so far.
The numbers can be negative. If the list is empty there is no largest one: in that case you return 0.
Examples
[3, 9, 4] → 9
[10, 3, 1] → 10
[7] → 7
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def largest_in_list(numbers):
passJavaScript
function largestInList(numbers) {
}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.