← Back to Data Structures & Algorithms
Question 542
Index Of The Largest
Index Of The Largest
Write index_of_max(values: list[int]) -> int that returns the index of the largest value, the earliest one when the largest appears more than once, and -1 for an empty list. Start a best index at 0, then loop over range(1, len(values)) and move best whenever a strictly larger value is found. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of space-separated integers (possibly empty); the tests print the index your function returns.
Expected Output:
1= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Data Structures & Algorithms
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.