Minimum and Maximum (Set 13)

Easy

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

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

Example 1

minAndMax()
Input
nums = [18, 291, 46, 233, -193, 167, 231, 56, -100, 2, 186, 145, 129, 80, -91, 224, 70, 207, -3, -81, 204, 37, 143, 177, -94, -189, 107, 282, -94, 139, 166, 180, 137, 178, 237, 178, -132, 51, -108, 259, 89, -2, -63, 158, 36, -4, -128, 178]
Output
[-193, 291]

Why

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

Example 2

minAndMax()
Input
nums = [-48, 179, 214, -70, 90, 100, -41, 15, 107, 174, -162, -102, 270, -86, -122, 112, 147, 18, 92, -14, 135, 118, -73, -180, -68, -134, 208, 212, 276, 19, 257, 126, -30, 197, 66, 240, 112, -56, 90, 153, -154, -185, 286, 88, 97, -30, -166, -174]
Output
[-185, 286]

Why

`minAndMax` returns `[-185, 286]` 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.