Android & iPhone apps are coming soon. Log in for a plan and reminders made for you →

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.

Your code · Python

Stuck?