Maximum Profit of Operating a Centennial Wheel — LeetCode 1599 Python Solution
MediumArraySimulation
- Problem
- #1599
- Reading time
- 4 min
- Source
- leetcode.com
The problem
You are the operator of a Centennial Wheel that has four gondolas, and each gondola has room for up to four people. You have the ability to rotate the gondolas counterclockwise, which costs you runningCost dollars.
Example
- Input
- customers = [8,3], boardingCost = 5, runningCost = 6
- Output
- 3
- Explanation
- The numbers written on the gondolas are the number of people currently there.
Python solution
Python
class Solution:
def minOperationsMaxProfit(
self, customers: List[int], boardingCost: int, runningCost: int
) -> int:
ans = -1
mx = t = 0
wait = 0
i = 0
while wait or i < len(customers):
wait += customers[i] if i < len(customers) else 0
up = wait if wait < 4 else 4
wait -= up
t += up * boardingCost - runningCost
i += 1
if t > mx:
mx = t
ans = i
return ansComplexity
| Measure | Complexity |
|---|---|
| Time | O(n), where n is the length of the `customers` array |
| Space | O(1) auxiliary |
Related problems
LeetCode 495Teemo AttackingEasyLeetCode 985Sum of Even Numbers After QueriesMediumLeetCode 1389Create Target Array in the Given OrderEasyLeetCode 1409Queries on a Permutation With KeyMediumLeetCode 1503Last Moment Before All Ants Fall Out of a PlankMediumLeetCode 1535Find the Winner of an Array GameMedium
Frequently asked questions
- How hard is LeetCode 1599. Maximum Profit of Operating a Centennial Wheel?
- LeetCode 1599. Maximum Profit of Operating a Centennial Wheel is rated Medium on LeetCode.
- What is the time complexity of LeetCode 1599. Maximum Profit of Operating a Centennial Wheel?
- The Python solution on this page runs in O(n), where n is the length of the `customers` array.
- What is the space complexity of LeetCode 1599. Maximum Profit of Operating a Centennial Wheel?
- The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 1599. Maximum Profit of Operating a Centennial Wheel cover?
- LeetCode 1599. Maximum Profit of Operating a Centennial Wheel is tagged Array and Simulation on LeetCode.