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 using dict() but time complexity is not good, Any help
n = int(input())
scores = sorted(set(map(int,input().split())))
m = int(input())
alice = map(int,input().split())
for first in alice:
d={}
rank=1
scores.append(first)
scores.sort(reverse=True)
d[scores[0]]=1
for i in range(1,len(scores)):
if scores[i]==scores[i-1]:
d[int(scores[i])]=rank
else:
rank=rank+1
d[int(scores[i])]=rank
print(d[first])
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 using dict() but time complexity is not good, Any help n = int(input()) scores = sorted(set(map(int,input().split()))) m = int(input()) alice = map(int,input().split()) for first in alice: d={} rank=1 scores.append(first) scores.sort(reverse=True) d[scores[0]]=1 for i in range(1,len(scores)): if scores[i]==scores[i-1]: d[int(scores[i])]=rank else: rank=rank+1 d[int(scores[i])]=rank print(d[first])