Maximum Value and Index (Set 10)

Easy

Given a non-empty array of integers nums, return [value, index] for the largest value. On a tie, return the first index.

Maximum Value and Index (Set 10) — the data. This set runs 4 cases: nums holds arrays of 40–44 items, with values from -49 to 90. The hidden cases are the largest of the set.

Example 1

maxValueAndIndex()
Input
nums = [46, 45, 23, -26, 88, -7, 57, -39, 16, -9, -8, -8, -23, 89, 2, 67, -15, 67, -2, -30, 40, 37, -36, 82, 7, 77, 3, 48, -18, 62, -18, 72, -16, 51, 66, -9, 37, 28, 60, 21]
Output
[89, 13]

Why

`maxValueAndIndex` returns `[89, 13]` for this input.

Example 2

maxValueAndIndex()
Input
nums = [81, -47, 36, 19, 37, 60, -9, 26, 33, 0, 49, 31, 7, 79, 56, 7, -7, 0, -46, -10, 68, 36, 68, -14, -8, -4, 39, -16, 1, -3, 34, 76, -17, 53, -26, -40, 19, -32, 15, 17, 35]
Output
[81, 0]

Why

`maxValueAndIndex` returns `[81, 0]` for this input.
Constraints
1 <= nums.length <= 10^5
-10^5 <= nums[i] <= 10^5
Every case in this set must pass: the first two are visible on Run, the last two unlock on Submit.

Topics

Arrays

Implement maxValueAndIndex in the editor and return the answer — printing it is never graded.