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.
defheadDrop(lst):result=1000000000000000000000000000iflst[0]>min(lst)and[xforxinlst[1:]ifx<lst[0]]!=[]:diff=lst[0]-max([xforxinlst[1:]ifx<lst[0]])ifdiff>0:result=diffreturnresultdefminimumLoss(price):# Write your code herel=[]ll=[price]whilell!=[]:price=ll.pop(0)l.append(headDrop(price))upper=[pforpinpriceifp>price[0]]lower=[pforpinpriceifp<price[0]]iflen(upper)>1:ll.append(upper)iflen(lower)>1:ll.append(lower)returnmin(l)minimumLoss([5,10,3])
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Loss
You are viewing a single comment's thread. Return to all comments →