We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importmathimportosimportrandomimportreimportsysfromtypingimportListdefoptimal(array:List):returned_values_left:list[int]=[]returned_values_right:list[int]=[]forindex,iteminenumerate(array):ifindex==0:returned_values_left.append(0)else:ifitem<array[index-1]:returned_values_left.append(index)else:returned_values_left.append(0)ifindex==len(array)-1:returned_values_right.append(0)else:ifitem<array[index+1]:returned_values_right.append(index+2)else:returned_values_right.append(0)return[returned_values_left,returned_values_right]## Complete the 'solve' function below.## The function is expected to return an INTEGER.# The function accepts INTEGER_ARRAY arr as parameter.#defsolve(arr):# Write your code herevalue=sys.maxsize*-1[left,right]=optimal(arr)forpositioninrange(len(arr)):new_value=left[position]*right[position]ifnew_value>value:value=new_valuereturnvalue
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Find Maximum Index Product
You are viewing a single comment's thread. Return to all comments →
This is my solution in python3