Minimum and Maximum (Set 5)

Easy

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

Minimum and Maximum (Set 5) — the data. This set runs 4 cases: nums holds arrays of 25–39 items, with values from -200 to 294. The hidden cases are the largest of the set.

Example 1

minAndMax()
Input
nums = [55, -49, 263, -148, 228, 257, 175, -115, 271, 70, -5, 181, -25, 39, 50, 177, -134, 12, 77, 169, 119, 238, -162, -97, -3, -196, -68, -137, 249, -141, -36, -94]
Output
[-196, 271]

Why

`minAndMax` returns `[-196, 271]` for this input.

Example 2

minAndMax()
Input
nums = [133, -140, 68, 222, -71, -8, 8, 65, 31, 101, 193, -82, 76, 262, 189, -143, 294, 83, -186, 282, 10, -115, 20, 115, 242]
Output
[-186, 294]

Why

`minAndMax` returns `[-186, 294]` 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.