Explore
ProGrad Programs
Placement Prep
Discussion Forum
About Us

Edit
Reply




Edit

  1. Home
  2. DiscussionForumPosting

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
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 !!!

Thank ()
Reply
16 days ago


ThunderKid
But 4 of my testcases are not running

Thank ()
16 days ago