Find the biggest
Inputs
values is a list of 1 to 12 whole numbers, each from -50 to 50.
Your tasks
- Create a number
bestand set it to the first number invalues. - Use a loop over
values. Whenever a number is larger thanbest, replacebestwith it. - Complete
biggestso it returnsbest. Return it, do not print it.
Example
With values = [3, 9, -2, 9, 5], biggest returns 9.
Rules
valuesalways has at least one number.- Do not start
bestat 0. All the numbers might be negative.
Test data
TEST DATA 1: values is [3, 9, -2, 9, 5]
TEST DATA 2: values is [-8, -3, -20]
Practice focus
One pass over a list to add, count, find the biggest and the smallest. Scanning an array once and keeping a running answer is the backbone of linear-time solutions.