Skip to content

Commit fbb79b7

Browse files
authored
Create maximum-profit-of-operating-a-centennial-wheel.py
1 parent ebe3ef7 commit fbb79b7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def minOperationsMaxProfit(self, customers, boardingCost, runningCost):
6+
"""
7+
:type customers: List[int]
8+
:type boardingCost: int
9+
:type runningCost: int
10+
:rtype: int
11+
"""
12+
max_run = -1
13+
i = max_prof = prof = waiting = 0
14+
run = 1
15+
while i < len(customers) or waiting > 0:
16+
if i < len(customers):
17+
waiting += customers[i] # each run i increases people by customers[i]
18+
i += 1
19+
boarding = min(waiting, 4) # greedy
20+
waiting -= boarding
21+
prof += boarding * boardingCost - runningCost
22+
if prof > max_prof:
23+
max_prof = prof
24+
max_run = run
25+
run += 1
26+
return max_run

0 commit comments

Comments
 (0)