Minimum and Maximum (Set 10)

Easy

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

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

Example 1

minAndMax()
Input
nums = [229, -101, -97, 139, 299, -86, -127, 62, 27, -55, 162, -93, 115, 281, -76, 154, -195, 161, 119, 67, 168, -1, 206, 287, 230, 250, 12, 138, -191, 43, 159, 67, -61, 83, -130, 253, 264, -146, 170, -73, 232, 80, -148, 21]
Output
[-195, 299]

Why

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

Example 2

minAndMax()
Input
nums = [114, -1, -13, -161, 105, -160, 63, -105, 216, 275, -38, 217, -37, 127, 277, 155, 298, 214, 105, -103, 186, 113, 172, 149, -128, 2, -61, -32, 38, 18, -172, -88, 70, -31, 50, 255, 117, 50, 236, 34, -187, -151, 151, -62]
Output
[-187, 298]

Why

`minAndMax` returns `[-187, 298]` 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.