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.
I have used two for loops in my solution and it failed in four test cases due to time complexity.you used one while and for loops but it turned out it is error clear how is this happening,what is the principle in time complexity.
scores=list(map(int,input().split()))
alice=list(map(int,input().split()))
climberank=[]
for i in alice:
temp=set(sorted(scores))
temp.add(i)
for index,value in enumerate(sorted(temp,reverse=True),1):
if value==i:
climberank.append(index)
temp.discard(i)
print(*climberank)
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 →
I have used two for loops in my solution and it failed in four test cases due to time complexity.you used one while and for loops but it turned out it is error clear how is this happening,what is the principle in time complexity.
scores=list(map(int,input().split())) alice=list(map(int,input().split())) climberank=[] for i in alice: temp=set(sorted(scores)) temp.add(i) for index,value in enumerate(sorted(temp,reverse=True),1): if value==i: climberank.append(index) temp.discard(i) print(*climberank)