Skip to content

Instantly share code, notes, and snippets.

@avinayak
Last active September 7, 2018 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avinayak/f40592b18ad02e60bfcf437c9b08bfce to your computer and use it in GitHub Desktop.
Save avinayak/f40592b18ad02e60bfcf437c9b08bfce to your computer and use it in GitHub Desktop.
def binsearch(a,q):
l = mid = 0
r = len(a) -1
while l<=r:
mid = (l+r)//2
if a[mid] == q:
return mid
elif a[mid]< q:
l = mid +1
elif a[mid]> q:
r = mid - 1
return r
# Complete the climbingLeaderboard function below.
def climbingLeaderboard(scores, alice):
board = []
ranks = []
for i in scores:
if len(board)==0 or board[0] != i:
board.insert(0,i)
for i in alice:
pos = len(board) - binsearch(board,i)
ranks.append(pos)
return ranks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment