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.
My code doesn't pass the execution time limits, does anyone know why?. Here it is:
'''findsthepositionoftheplayerbasedontheirscore.Wecomparetheirscorewiththescoresofalltheotherplayers.'''deforder(ranked,element):storage=[]storage.append((1,ranked[0]))index=2forscoreinranked[1:]:ifstorage[-1][1]==score:continueelse:ele=(index,score)storage.append(ele)index+=1forpairinstorage:if(pair[1]==element):returnpair[0]'''Thiswillinserttheplayer'sscoreinitscorrectpositionintherankedlist.Thenitwillfindthepositionofthatscoreintherankedlistusingtheorderfunction.ThiswillbestoredintheoutList,whichiswhatwillbereturned'''defclimbingLeaderboard(ranked,player):# Write your code hereoutList=[]forscoreinplayer:flag=Trueifscore>ranked[0]:ranked.insert(0,score)outList.append(order(ranked,score))continueforjinrange(0,len(ranked)-1):ifranked[j]>=score>=ranked[j+1]:ranked.insert(j+1,score)outList.append(order(ranked,score))flag=Falsebreakifflag:ranked.append(score)outList.append(order(ranked,score))returnoutList
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Climbing the Leaderboard
You are viewing a single comment's thread. Return to all comments →
My code doesn't pass the execution time limits, does anyone know why?. Here it is: