MediumNo. 1599
Maximum Profit of Operating a Centennial Wheel — LeetCode 1599 Python Solution
- Topics
- Array, Simulation
- 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
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
- Time
- O(n)where n is the length of the `customers` array
- Space · auxiliary
- O(1)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0495 | Teemo Attacking | Easy |
| 0985 | Sum of Even Numbers After Queries | Medium |
| 1389 | Create Target Array in the Given Order | Easy |
| 1409 | Queries on a Permutation With Key | Medium |
| 1503 | Last Moment Before All Ants Fall Out of a Plank | Medium |
| 1535 | Find the Winner of an Array Game | Medium |
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.