Minimum and Maximum (Set 3)

Easy

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

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

Example 1

minAndMax()
Input
nums = [248, 0, -60, 168, 163, 224, 230, 54, -45, 143, -153, -82, -29, 251, 18, 213, -195, 121, -4, 202, 54, 91]
Output
[-195, 251]

Why

`minAndMax` returns `[-195, 251]` for this input.

Example 2

minAndMax()
Input
nums = [137, 199, -113, -47, -79, -55, 162, 47, -167, 216, 76, 87, 300]
Output
[-167, 300]

Why

`minAndMax` returns `[-167, 300]` 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.