Last active
September 7, 2018 11:01
-
-
Save avinayak/f40592b18ad02e60bfcf437c9b08bfce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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