-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCutoffRank.py
38 lines (31 loc) · 901 Bytes
/
CutoffRank.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# SLOW
"""
def countLevelUpPlayers(cutOffRank, num, scores):
scores.sort()
res = 0
if cutOffRank == 0:
return 0
for i in range(num):
if scores[num - 1 - i] > 0 and i < cutOffRank - 1:
res += 1
elif (scores[num - 1 - i] == scores[num - 1 - cutOffRank + 1]):
res += 1
return res
"""
# Correct
def countLevelUpPlayers(cutOffRank, num, scores):
scores.sort()
if cutOffRank == 0:
return 0
res = cutOffRank
if (scores[num - cutOffRank] == 0):
counter = 0
while num - cutOffRank + counter < num and scores[num - cutOffRank + counter] == 0:
counter += 1
res -= 1
return res
i = cutOffRank
while ((num - 1 - i) >= 0 and scores[num - 1 - i] == scores[num - cutOffRank]):
res += 1
i += 1
return res