Explore
ProGrad Programs
Placement Prep
About Us

Edit
Reply

Edit

### ThunderKid

ngjhg

Faceprep ID : 1501328

1 Thanks

Can any one optimize this code(python 3) for the given problem ? https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem def app(l, n): count = 1 for i in range(len(l)): if l[i] <= n: print(l[i], n) index = i count = 0 break if count == 1: l.append(n) else: l = l[:i] + [n] + l[i:] return l # Complete the climbingLeaderboard function below. def climbingLeaderboard(scores, alice): s = [] for i in range(0,len(scores)): if scores[i] not in s: s.append(scores[i]) l = [] for i in range(0,len(alice)): s = app(s,alice[i]) l.append(s.index(alice[i])+1) s.remove(alice[i]) print(s) return(l) Thanks in advance

1 Thanks 1 Comment
POORNACHAND 16 days ago
def app(l, n):
for i,val in enumerate(l):
if val <= n:
print(val, n)
return l[:i] + [n] + l[i:]
return l+[n]
def climbingLeaderboard(scores, alice):
s ,l = sorted(list(set(scores)),reverse=True),[]
for val in alice:
s = app(s,val)
l.append(s.index(val)+1)
s.remove(val)
print(s)
return(l)

Hope it would Work !!!

No More Posts