Minimum and Maximum (Set 8)

Easy

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

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

Example 1

minAndMax()
Input
nums = [0, -182, 87, 221, 136, -157, -144, -152, 166, -120, 258, 221, -19, 205, 292, -77, 14, -123, 280, 269, -194, 190, 49, 0, 276, 192, -194, 190, 246, 295, 55, 60, -8, 231, -83, 58]
Output
[-194, 295]

Why

`minAndMax` returns `[-194, 295]` for this input.

Example 2

minAndMax()
Input
nums = [-68, -146, 217, 49, 164, -49, 67, 288, -157, -11, -70, -157, 263, 193, -8, 2, 264, 273, 151, 26, 93, 1, -122, 130, -30, 21, 123, -151, 91, 195, 175, 212, 100, 155, -26, 29, 84, 169, -116, -33, 297, -180, 33, 200]
Output
[-180, 297]

Why

`minAndMax` returns `[-180, 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.