Minimum and Maximum (Set 14)

Easy

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

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

Example 1

minAndMax()
Input
nums = [-157, -29, -131, 273, 174, 239, 96, -103, -78, 88, 117, 4, 82, 176, 230, -6, -127, 124, -16, 199, 102, 101, 213, 92, 17, -122, -189, -80, -46, 10, -18, 242, -51, 230, 221, -176, 284, 215, -79, -129, 249, -100, -8, 63, -138, 16, -168, -158]
Output
[-189, 284]

Why

`minAndMax` returns `[-189, 284]` for this input.

Example 2

minAndMax()
Input
nums = [-91, -186, 63, -83, 287, 141, -1, -59, 97, 246, 43, -124, 225, 79, 210, -91, 166, -106, -159, -17, -124, 26, -55, -91, 69, 158, 98, 191, 300, 228, -12, 45, 10, 62, 57, 77, -169, -29, 66, -31, 141, 142, -69, 170, 238, -157, -81, 73]
Output
[-186, 300]

Why

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