Minimum and Maximum (Set 11)

Easy

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

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

Example 1

minAndMax()
Input
nums = [145, 220, -115, -190, 22, 97, 178, -40, 35, -41, 158, 201, -1, 140, 151, 91, 1, 288, -44, -84, -14, 240, 130, -40, -157, 271, 297, 60, 78, 191, -126, -179, 174, 208, -97, -162, 176, -30, -113, -24, -166, 90, 44]
Output
[-190, 297]

Why

`minAndMax` returns `[-190, 297]` for this input.

Example 2

minAndMax()
Input
nums = [-94, -109, -15, -146, 224, -187, 71, -85, 177, 135, -66, 52, 264, 286, 122, 163, -9, 219, 214, 274, -47, -6, 172, -185, -57, 261, 239, 50, 191, 297, 122, 90, -164, 295, 131, 143, 88, 61, 245, -170, 187, 93, 96, 212, -24]
Output
[-187, 297]

Why

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