Created
March 8, 2020 23:06
-
-
Save BharathKumarS/08e02ce159059e0bf6444548bc684201 to your computer and use it in GitHub Desktop.
HackerRanck, Climbing the Leaderboard challenge. 7/11 test cases passed. I welcome you to modify my code. Thank you for the help.
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
class Score_board: | |
def board(self, scores, alice): | |
self.boardScores = sorted(set(scores), reverse=True) | |
alice_rank = list(map(self.rankBoard,alice)) | |
return alice_rank | |
def rankBoard(self, current): | |
score_bank = self.boardScores | |
midIndex = len(score_bank)//2 | |
while midIndex > 0: | |
if current in score_bank: | |
return(self.boardScores.index(current)+1) | |
elif current < score_bank[midIndex]: | |
score_bank = score_bank[midIndex:] | |
midIndex = len(score_bank)//2 | |
elif current > score_bank[midIndex]: | |
score_bank = score_bank[:midIndex] | |
midIndex = len(score_bank)//2 | |
else: | |
boardIndex = self.boardScores.index(score_bank[0]) | |
if current in score_bank: | |
return(self.boardScores.index(current)+1) | |
elif current > score_bank[0] and boardIndex == 0: | |
return(1) | |
elif current < score_bank[0] and boardIndex == (len(self.boardScores)-1): | |
return(boardIndex + 2) | |
elif current > score_bank[0]: | |
return(boardIndex) | |
elif current < score_bank[0]: | |
return(boardIndex + 2) | |
if __name__ == "__main__": | |
scores_count = int(input()) | |
tScores = list(map(int, input().rstrip().split())) | |
alice_count = int(input()) | |
aScore = list(map(int, input().rstrip().split())) | |
coord = Score_board() | |
aRank = coord.board(tScores,aScore) | |
print(aRank) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment