-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel46.py
More file actions
23 lines (17 loc) · 729 Bytes
/
level46.py
File metadata and controls
23 lines (17 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Elections are in progress!
# Given an array of the numbers of votes given to each of the candidates so far,
# and an integer k equal to the number of voters who haven't cast their vote yet,
# find the number of candidates who still have a chance to win the election.
# The winner of the election must secure strictly more votes than any other candidate.
# If two or more candidates receive the same (maximum) number of votes, assume there is no winner at all.
def solution(votes, k):
if votes.count(max(votes))>1 and k==0:
return 0
elif k==0:
return 1
count = 0
max_v = max(votes)
for i in range(len(votes)):
if (votes[i]+k)>max_v:
count+=1
return count