Warm-ups · 1 of 24
Largest and smallest element
Given a non-empty array of integers, return [smallest, largest].
Examples
Input nums = [3, 7, 1, 9, 4]
Output [1, 9]
Input nums = [-2, -8, -1]
Output [-8, -1]
All negative: don't start your “largest” at 0.
📘 New to this? Indexing and walking through an array explains the idea in a few minutes.