Minimum and Maximum (Set 6)

Easy

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

Minimum and Maximum (Set 6) — the data. This set runs 4 cases: nums holds arrays of 24–46 items, with values from -194 to 300. The hidden cases are the largest of the set.

Example 1

minAndMax()
Input
nums = [-64, -137, 64, 253, -38, -69, -181, -193, 224, 33, -41, -2, -150, -139, -26, 245, -34, 95, 108, -9, -60, -193, 240, 293, 291, 177, 300, 292, 150, -73, 139, 181, -18, 157, 209, 221, -152, 45, 212, 284, -104, 115, 88, -30, 139, -182]
Output
[-193, 300]

Why

`minAndMax` returns `[-193, 300]` for this input.

Example 2

minAndMax()
Input
nums = [-190, 100, 223, 192, 177, 57, 79, -106, 107, 251, 205, -17, 60, 199, 1, 69, 219, -159, 97, 90, -3, -80, 101, -121, 89, 145, -51, -9, 8, -157, -16, 209, 142, 82, 21, 220, 146, 53, 13, 91, 123, 17, -96]
Output
[-190, 251]

Why

`minAndMax` returns `[-190, 251]` 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.