Find Index of Maximum Element - aloalgo

Find Index of Maximum Element

Very Easy

You are given an array of integers nums, find the index of its maximum element. If there are multiple occurrences of the maximum element, return the index of the first occurrence.

If the array is empty, return -1.

Example 1

Input
[1, 3, 2]
Output
1
Explanation:

The maximum element is 3, which is at index 1.

Example 2

Input
[5, 2, 5, 1]
Output
0
Explanation:

The maximum element is 5. The first occurrence is at index 0.

Example 3

Input
[-10, -5, -20]
Output
1
Explanation:

The maximum element is -5, which is at index 1.

Loading...
Input
[1, 3, 2]
Output
1

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!