Maximum Value and Index (Set 5)

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 5) — the data. This set runs 4 cases: nums holds arrays of 21–33 items, with values from -49 to 89. The hidden cases are the largest of the set.

Example 1

maxValueAndIndex()
Input
nums = [12, 0, -24, 50, 89, -41, 70, -18, 83, 8, 79, -26, 25, -36, 87, -38, -23, 16, 79, 79, -49, 41, 56, 88, -47, 83, -10, 40, 49, -31, 21, 9, 41]
Output
[89, 4]

Why

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

Example 2

maxValueAndIndex()
Input
nums = [-41, 18, 85, -25, 15, 38, -46, 1, 23, -25, 11, -10, 7, 50, 83, -8, 64, -36, 61, 83, 13]
Output
[85, 2]

Why

`maxValueAndIndex` returns `[85, 2]` 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.