Maximum Value and Index (Set 7)

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

Example 1

maxValueAndIndex()
Input
nums = [83, -38, -15, 4, -32, 68, 25, 69, 16, 17, 75, 66, 49, -32, 26, -21, -21, -45, -35, -24, -37, 65, 13, -34, 76, -39, -31, -13, 44, 6, 10, -11, -12, 68, 6, 71, 68, -49, -22, -10]
Output
[83, 0]

Why

`maxValueAndIndex` returns `[83, 0]` for this input.

Example 2

maxValueAndIndex()
Input
nums = [88, 5, -38, 14, -23, 33, 74, -25, 23, -26, -49, 51, 45, 13, -15, 82, -19, 77, 21, 27, 90, -50, 16, 66, -36, -15, 41, -22, -49, 6, 38, 9]
Output
[90, 20]

Why

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