Index of the Maximum
mediumQuestion 566Write a function int indexOfMax(const vector<int>& v) that returns the 0-based index of the largest element in v using max_element (from <algorithm>). If the largest value appears more than once, return the index of its first occurrence. You may assume v is not empty.
The test prints the returned index on its own line. For {1, 5, 2, 9} it prints 3; for {9, 1, 9} it prints 0.
Do NOT write a main function.
Expected output
3 0
= newline. The output ends with a newline, so print one after the last line.
Hints2 available
Sign in to use hintsTopics
STL ContainersIterators
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.