IN PYTHON 3 FOLLOW INSTRUCTIONS Problem Complete the function, indexOfMax(), to
ID: 3740392 • Letter: I
Question
IN PYTHON 3
FOLLOW INSTRUCTIONS
Problem
Complete the function, indexOfMax(), to recursively locate the index of the maximum integer in an array of integers.
If there are multiple items of the maximum value, return the index of the first one.
Example
indexOfMax([1, 2, 3, 4, 4]) returns 3
indexOfMax([1]) returns 0
indexOfMax([9, 8 10]) returns 2
back to classroom run Instructions from your teacher Problem Complete the function, index0fMax(), to recursively locate the index of the maximum integer in an array of integers. If there are multiple items of the maximum value, return the index of the first one Example indexofMax ([1, 2, 3, 4, 4]) returns 3 indexofMax ([1]) returns0 indexofMax ([9, 8 10]) returns 2Explanation / Answer
def indexOfMax(arr,i):
#if i exceeds length of arr
if i>len(arr):
return -1
#get the index of max element in the right subarray
Max_right=indexOfMax(arr, i+1)
if Max_right== -1:
return i
# if the element in the right subarray is smaller than the current element
return i
print(indexOfMax([1,2,3,4,4], 0))
print(indexOfMax([1], 0))
print(indexOfMax([9, 8, 10], 0))