Minimum and Maximum (Set 12)

Easy

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

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

Example 1

minAndMax()
Input
nums = [224, -75, 1, -32, 273, 193, -38, -142, -175, 42, 97, -73, 40, -28, 144, 249, 275, 19, 147, 104, -43, 1, -18, 27, -14, 199, -199, 271, -164, -28, 251, 294, -44, -154, 130, -45, 101, 100, -163, 286, -73, 150, -23, -157, 214, -130, 266, -10]
Output
[-199, 294]

Why

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

Example 2

minAndMax()
Input
nums = [142, 114, -124, 265, 28, 168, 164, 65, 150, 290, -2, 9, -60, 43, -87, 157, 130, 194, 162, 58, 199, -11, 80, -105, 263, 143, -170, -98, 118, -109, -130, -96, -70, -125, -169, -74, -175, 111, 149, 56, -68, 1, -91, -132, -131, -168, 4, -154]
Output
[-175, 290]

Why

`minAndMax` returns `[-175, 290]` 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.