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 1) — the data. This set runs 4 cases: nums holds arrays of 4–9 items, with values from -50 to 87. The hidden cases are the largest of the set.
Example 1
maxValueAndIndex()
Input
nums =[71,-10,29,87]
Output
[87,3]
Why
`maxValueAndIndex` returns `[87, 3]`forthisinput.
Example 2
maxValueAndIndex()
Input
nums =[58,37,37,32,-4]
Output
[58,0]
Why
`maxValueAndIndex` returns `[58, 0]`forthisinput.
Constraints
1<=nums.length<=10^5-10^5<= nums[i]<=10^5
Every caseinthisset 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.