Minimum and Maximum (Set 9)

Easy

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

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

Example 1

minAndMax()
Input
nums = [90, 4, 76, 277, -51, -128, 54, -3, 28, 21, 31, 30, 60, 235, -164, -135, -169, 45, 118, -58, 232, 6, 196, -97, 199, -33, 287, -31, 122, -51, 216, 26, 56, 191, -18, 118, 42, 118, 87, -90, -50, 261, 66, 194, -28, 114]
Output
[-169, 287]

Why

`minAndMax` returns `[-169, 287]` for this input.

Example 2

minAndMax()
Input
nums = [265, 209, 89, 71, -53, 239, 277, 180, -62, 35, -80, -55, 219, -12, 269, 127, -36, 79, -167, 91, 237, 238, 195, -49, 135, -111, 164, -190, -116, -199, -147, 110, 289, -188, 171, 259, -182, 249, -198, 288, 176, 260, 69, 276]
Output
[-199, 289]

Why

`minAndMax` returns `[-199, 289]` 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.