Leetcode #1599: Maximum Profit of Operating a Centennial Wheel
In this guide, we solve Leetcode #1599 Maximum Profit of Operating a Centennial Wheel in Python and focus on the core idea that makes the solution efficient.
You will see the intuition, the step-by-step method, and a clean Python implementation you can use in interviews.

Problem Statement
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.
Quick Facts
- Difficulty: Medium
- Premium: No
- Tags: Array, Simulation
Intuition
The rules are explicit, so simulating the process step by step is safest.
Careful state updates prevent subtle bugs.
Approach
Translate the rules into state updates and apply them in order.
Track the final state or aggregate as required.
Steps:
- Translate rules into state updates.
- Iterate for each step.
- Return the final state.
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.
1. 8 customers arrive, 4 board and 4 wait for the next gondola, the wheel rotates. Current profit is 4 * $5 - 1 * $6 = $14.
2. 3 customers arrive, the 4 waiting board the wheel and the other 3 wait, the wheel rotates. Current profit is 8 * $5 - 2 * $6 = $28.
3. The final 3 customers board the gondola, the wheel rotates. Current profit is 11 * $5 - 3 * $6 = $37.
The highest profit was $37 after rotating the wheel 3 times.
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 ans
Complexity
The time complexity is , where is the length of the customers array. The space complexity is .
Edge Cases and Pitfalls
Watch for boundary values, empty inputs, and duplicate values where applicable. If the problem involves ordering or constraints, confirm the invariant is preserved at every step.
Summary
This Python solution focuses on the essential structure of the problem and keeps the implementation interview-friendly while meeting the constraints.