Maximum Value and Index (Set 3)

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

Example 1

maxValueAndIndex()
Input
nums = [-6, 62, 58, 56, 5, 33, 84, 15, -28, 20, 18, -42, 81, 62, -50, 33, -47, 73, 37]
Output
[84, 6]

Why

`maxValueAndIndex` returns `[84, 6]` for this input.

Example 2

maxValueAndIndex()
Input
nums = [18, 87, 48, 55, 29, 77, -43, 73, 87, -6, 71, 32, 58, 20]
Output
[87, 1]

Why

`maxValueAndIndex` returns `[87, 1]` 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.