-
Notifications
You must be signed in to change notification settings - Fork 0
/
standing_ovation.py
31 lines (29 loc) · 1.03 KB
/
standing_ovation.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
#
# Google Code Jam Qualification Round 2015
#
# Your friend is a prima donna in an opera, and you want
# the audience to give her a standing ovation. Each audience
# member has some level of shyness, and will only stand when some
# number of people standing before they themselves stand.
# You can invite some number of friends that will give standing
# ovations. What is the minimum number of friends you need
# to invite in order to guarantee a standing ovation? (not
# including yourself)
#
def standing_ovation(audience):
'''
Given an audience array indexed by shyness level, return the
minimum number of friends to bring to guarantee a standing
ovation.
'''
standing = 0
friends = 0
for shyness, n in enumerate(audience):
newFriends = 0
if shyness == 0 and n == 0: # initial 'stander'
newFriends = 1
elif shyness >= standing and n == 0: # next shyness won't stand
newFriends = 1
friends += newFriends
standing += n + newFriends
return friends