Maximum Value and Index (Set 13)

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

Example 1

maxValueAndIndex()
Input
nums = [-49, 44, -22, -45, 88, 1, 67, 66, -24, -6, 6, -3, -47, 1, -18, 15, 45, 8, -26, 61, 80, -10, -27, 58, 33, 57, 36, 42, -36, 89, 49, -5, -2, -47, 14, -3, 43, -32, 88, 4, -19, 0, -2, 4, -7, -9, 31, -17]
Output
[89, 29]

Why

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

Example 2

maxValueAndIndex()
Input
nums = [85, -5, -18, -46, 47, 81, -39, 83, -10, 5, 1, 90, -1, 86, -13, 90, 23, 15, -18, 63, 73, -41, -37, 27, 30, 18, 29, 76, 83, 24, -35, 11, -20, 10, 43, 2, -41, -5, 46, 53, -43, 29, 6, -15, 72, -13, 34, 49]
Output
[90, 11]

Why

`maxValueAndIndex` returns `[90, 11]` 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.