Maximum Value and Index (Set 11)

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 11) — the data. This set runs 4 cases: nums holds arrays of 45–47 items, with values from -50 to 88. The hidden cases are the largest of the set.

Example 1

maxValueAndIndex()
Input
nums = [9, -31, 86, 76, -48, 18, 24, 87, -29, 13, -13, 75, 63, 55, 75, 65, 39, 75, -31, -46, 81, -20, -34, -18, -9, -35, 53, -44, -25, 81, -41, -39, 75, 10, -40, 12, -50, 1, 41, 67, 63, 60, 71, 10, 13, 71, 32]
Output
[87, 7]

Why

`maxValueAndIndex` returns `[87, 7]` for this input.

Example 2

maxValueAndIndex()
Input
nums = [-18, -18, 46, -46, -36, 29, -14, -26, -21, -47, -29, 50, 79, 24, 71, -2, 31, 53, 24, 59, 23, -30, 65, -39, -18, -41, -33, 15, -32, -21, 75, -48, -46, -25, 70, -34, -28, -14, -46, -11, 42, 23, -43, 59, -2]
Output
[79, 12]

Why

`maxValueAndIndex` returns `[79, 12]` 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.