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.
Python O(n + m) solution. This is better than using binary search tree, which are usually O(m*log n)
defclimbingLeaderboard(ranked:list[int],player:list[int])->list[int]:# Write your code hereranked=[float("inf")]+rankedel_ranked_dict={ranked[0]:0}foriinrange(1,len(ranked)):ifranked[i]==ranked[i-1]:el_ranked_dict[ranked[i]]=el_ranked_dict[ranked[i-1]]else:el_ranked_dict[ranked[i]]=el_ranked_dict[ranked[i-1]]+1last_index=len(ranked)result=[]forscoreinplayer:foriinrange(last_index,0,-1):el=ranked[i-1]ifel>score:last_index=iresult.append(el_ranked_dict[el]+1)breakreturnresult
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Non-Divisible Subset
You are viewing a single comment's thread. Return to all comments →
Python O(n + m) solution. This is better than using binary search tree, which are usually O(m*log n)