Minimum and Maximum (Set 7)

Easy

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

Minimum and Maximum (Set 7) — the data. This set runs 4 cases: nums holds arrays of 29–44 items, with values from -198 to 296. The hidden cases are the largest of the set.

Example 1

minAndMax()
Input
nums = [-48, 218, -191, -171, -189, -168, -120, -139, 102, 134, -13, 157, 91, 212, -61, 10, 201, 206, -30, 215, -6, -114, 221, -181, -26, 25, 91, 95, 71, 211]
Output
[-191, 221]

Why

`minAndMax` returns `[-191, 221]` for this input.

Example 2

minAndMax()
Input
nums = [121, 264, -103, 282, 60, 199, -188, 168, -175, 238, -60, -150, 9, -6, 277, 150, -51, -64, 119, -149, 111, 179, 56, 205, -97, 68, 18, -161, 48, 245, 54, -62, -39, 20, 29, -42, 296, 9, 49, -89, -62, -170, -122, -129]
Output
[-188, 296]

Why

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