We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I solved it this way with Python: 1. put all the numbers in one sorted array followed the rule that the start of the range must be before the end of the range at the same point. For that I converted int to float and for the start of the range I deducted 0.2 for players and 0.1 for shots, and for the end added. 2. loop through that array
def solve(shots, players):
# Write your code here
cur_shots, cur_players, strenths = 0, 0, 0
arr_pl_sh = []
for i in range(len(players)):
arr_pl_sh.append(float(players[i][0]) - 0.2)
arr_pl_sh.append(float(players[i][1]) + 0.2)
for i in range(len(shots)):
arr_pl_sh.append(float(shots[i][0]) - 0.1)
arr_pl_sh.append(float(shots[i][1]) + 0.1)
arr_pl_sh.sort()
for x in arr_pl_sh:
if (str(x)[-1] == "8"):
cur_players += 1
strenths += cur_shots
elif (str(x)[-1] == "9"):
cur_shots += 1
strenths += cur_players
elif (str(x)[-1] == "2"):
cur_players -= 1
elif (str(x)[-1] == "1"):
cur_shots -= 1
return strenths
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Mr. X and His Shots
You are viewing a single comment's thread. Return to all comments →
I solved it this way with Python: 1. put all the numbers in one sorted array followed the rule that the start of the range must be before the end of the range at the same point. For that I converted int to float and for the start of the range I deducted 0.2 for players and 0.1 for shots, and for the end added. 2. loop through that array def solve(shots, players): # Write your code here cur_shots, cur_players, strenths = 0, 0, 0 arr_pl_sh = [] for i in range(len(players)): arr_pl_sh.append(float(players[i][0]) - 0.2) arr_pl_sh.append(float(players[i][1]) + 0.2) for i in range(len(shots)): arr_pl_sh.append(float(shots[i][0]) - 0.1) arr_pl_sh.append(float(shots[i][1]) + 0.1) arr_pl_sh.sort() for x in arr_pl_sh: if (str(x)[-1] == "8"): cur_players += 1 strenths += cur_shots elif (str(x)[-1] == "9"): cur_shots += 1 strenths += cur_players elif (str(x)[-1] == "2"): cur_players -= 1 elif (str(x)[-1] == "1"): cur_shots -= 1 return strenths