CJCoding With Joseph
15free / daySign inCreate account

Index of the Maximum

Write 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 — print one after the last line.

Hints2 available
Topics:
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.