Minimum and Maximum (Set 2)

Easy

Given a non-empty array of integers nums, return [min, max] computed in a single pass.

Minimum and Maximum (Set 2) — the data. This set runs 4 cases: nums holds arrays of 9–15 items, with values from -195 to 284. The hidden cases are the largest of the set.

Example 1

minAndMax()
Input
nums = [217, 105, 268, 14, 249, 127, -74, -90, 262, 198, 167, 116]
Output
[-90, 268]

Why

`minAndMax` returns `[-90, 268]` for this input.

Example 2

minAndMax()
Input
nums = [89, -191, -192, 88, 79, 274, 218, 73, 56]
Output
[-192, 274]

Why

`minAndMax` returns `[-192, 274]` for this input.
Constraints
1 <= nums.length <= 10^5
-10^9 <= nums[i] <= 10^9
Every case in this set must pass: the first two are visible on Run, the last two unlock on Submit.

Topics

Arrays

Implement minAndMax in the editor and return the answer — printing it is never graded.