Minimum and Maximum (Set 4)

Easy

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

Minimum and Maximum (Set 4) — the data. This set runs 4 cases: nums holds arrays of 19–33 items, with values from -199 to 299. The hidden cases are the largest of the set.

Example 1

minAndMax()
Input
nums = [125, 60, -52, 283, 44, 280, -14, -173, 123, 196, 223, 14, 9, 177, 270, -44, -199, -70, 30, -98, 62, 168, 38, 176, -180, 48, 89, 180, 254]
Output
[-199, 283]

Why

`minAndMax` returns `[-199, 283]` for this input.

Example 2

minAndMax()
Input
nums = [163, 269, 46, -49, 137, 142, -113, 107, 275, 160, 201, -72, -188, 179, 165, 47, 267, -179, 259]
Output
[-188, 275]

Why

`minAndMax` returns `[-188, 275]` 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.