Maximum Value and Index (Set 2)

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

Example 1

maxValueAndIndex()
Input
nums = [-48, -45, 16, 24, 27, 19, -5, -43, 56, 78, -26, 23, 0]
Output
[78, 9]

Why

`maxValueAndIndex` returns `[78, 9]` for this input.

Example 2

maxValueAndIndex()
Input
nums = [-21, 43, 37, 22, -42, 67, 41, 19, -37, -14, 16, 88, 79]
Output
[88, 11]

Why

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