Maximum Value and Index (Set 4)

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

Example 1

maxValueAndIndex()
Input
nums = [12, 60, 80, 86, 36, 17, -13, -8, 36, 59, 46, 36, 24, 2, -48, -7, -18, 43, 15, 37, 40, 1, 33, -29, 61, 6]
Output
[86, 3]

Why

`maxValueAndIndex` returns `[86, 3]` for this input.

Example 2

maxValueAndIndex()
Input
nums = [69, 3, 24, 81, -47, -40, 34, 80, 21, 45, 9, 35, 45, 31, -17, 73, 88, -15, -43, 51, -28, 33, -14, -26, 28, -13, 53]
Output
[88, 16]

Why

`maxValueAndIndex` returns `[88, 16]` 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.