LeetCode Problem

How to Solve Maximum Profit of Operating a Centennial Wheel

The problem asks you to maximize profit while operating a Centennial Wheel, taking into account customer arrivals, boarding costs, and rotation costs. By simulating the boarding process and calculating the profit after each rotation, you need to determine the highest possible profit. The solution should track customer flow, adjust for the gondola capacity, and optimize the stopping point for maximum profit.

GhostInterview Help

Need help with Maximum Profit of Operating a Centennial Wheel without spending extra time grinding it?

GhostInterview can read Maximum Profit of Operating a Centennial Wheel from a screenshot, generate the answer path, explain the complexity, and support solver-first interview workflows when you need direct help fast.

Screenshot Input

Capture the prompt fast instead of rewriting the problem by hand.

Answer + Complexity

Get the solution path, trade-offs, and complexity summary in one pass.

Stealth Workflow

Stay outside captured layers on supported screen-share workflows.

Problem #1599Array plus SimulationReviewed 2026-03-08
Difficulty
Medium
Primary pattern
Array plus Simulation
Answer-first problem summary
Step-by-step approach and complexity
GhostInterview solver workflow

The problem asks you to maximize profit while operating a Centennial Wheel, taking into account customer arrivals, boarding costs, and rotation costs. By simulating the boarding process and calculating the profit after each rotation, you need to determine the highest possible profit. The solution should track customer flow, adjust for the gondola capacity, and optimize the stopping point for maximum profit.

Problem Statement

You are operating a Centennial Wheel with four gondolas, each holding up to four customers. The wheel rotates counterclockwise, and each rotation costs you runningCost dollars. At each rotation, a new group of customers arrives, and each customer boards the gondola at a boardingCost price. You need to calculate the maximum profit after a certain number of rotations, considering both the cost and the revenue generated.

You can stop the wheel at any time, but continuing may either increase or decrease the total profit. The number of customers waiting at the wheel can exceed the gondola capacity of four, and only the first four customers can board at any given rotation. If no positive profit is possible after rotating through all customers, return -1.

Examples

Example 1

Input: customers = [8,3], boardingCost = 5, runningCost = 6

Output: 3

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.

Example 2

Input: customers = [10,9,6], boardingCost = 6, runningCost = 4

Output: 7

  1. 10 customers arrive, 4 board and 6 wait for the next gondola, the wheel rotates. Current profit is 4 * $6 - 1 * $4 = $20.
  2. 9 customers arrive, 4 board and 11 wait (2 originally waiting, 9 newly waiting), the wheel rotates. Current profit is 8 * $6 - 2 * $4 = $40.
  3. The final 6 customers arrive, 4 board and 13 wait, the wheel rotates. Current profit is 12 * $6 - 3 * $4 = $60.
  4. 4 board and 9 wait, the wheel rotates. Current profit is 16 * $6 - 4 * $4 = $80.
  5. 4 board and 5 wait, the wheel rotates. Current profit is 20 * $6 - 5 * $4 = $100.
  6. 4 board and 1 waits, the wheel rotates. Current profit is 24 * $6 - 6 * $4 = $120.
  7. 1 boards, the wheel rotates. Current profit is 25 * $6 - 7 * $4 = $122. The highest profit was $122 after rotating the wheel 7 times.

Example 3

Input: customers = [3,4,0,5,1], boardingCost = 1, runningCost = 92

Output: -1

  1. 3 customers arrive, 3 board and 0 wait, the wheel rotates. Current profit is 3 * $1 - 1 * $92 = -$89.
  2. 4 customers arrive, 4 board and 0 wait, the wheel rotates. Current profit is 7 * $1 - 2 * $92 = -$177.
  3. 0 customers arrive, 0 board and 0 wait, the wheel rotates. Current profit is 7 * $1 - 3 * $92 = -$269.
  4. 5 customers arrive, 4 board and 1 waits, the wheel rotates. Current profit is 11 * $1 - 4 * $92 = -$357.
  5. 1 customer arrives, 2 board and 0 wait, the wheel rotates. Current profit is 13 * $1 - 5 * $92 = -$447. The profit was never positive, so return -1.

Constraints

  • n == customers.length
  • 1 <= n <= 105
  • 0 <= customers[i] <= 50
  • 1 <= boardingCost, runningCost <= 100

Solution Approach

Simulate the Process

Simulate each rotation by tracking the number of customers boarding, calculating profit after each rotation, and adjusting for the gondola's capacity. This simulation approach captures the dynamic change in profit as customers board the gondolas.

Track Profit Calculation

For each rotation, calculate profit as revenue (boardingCost * number of customers boarded) minus the cost of running the wheel (runningCost). Keep track of the highest profit encountered during the simulation.

Determine Optimal Stopping Point

Monitor whether continuing to the next rotation is profitable. If profit after the next rotation is less than the current maximum, stop and return the highest profit.

Complexity Analysis

MetricValue
TimeDepends on the final approach
SpaceDepends on the final approach

The time complexity is O(n) because the solution iterates through each customer arrival once. The space complexity is O(1) as only a few variables are needed for tracking the current state of the simulation.

What Interviewers Usually Probe

  • Candidate understands how to simulate the boarding process and calculate profits.
  • The candidate demonstrates the ability to handle dynamic adjustments in customer flow and gondola capacity.
  • The candidate successfully identifies the optimal stopping point to maximize profit.

Common Pitfalls or Variants

Common pitfalls

  • Overcomplicating the calculation of profit by not directly tracking revenue and cost per rotation.
  • Failing to consider the gondola capacity limit when customers exceed the number waiting to board.
  • Not accounting for the scenario where no positive profit can be made, and returning -1.

Follow-up variants

  • Modify the problem by introducing different gondola capacities for different rotations.
  • Add a restriction that requires a certain number of customers to always board the wheel, regardless of the gondola space.
  • Simulate the problem under different customer behavior models, such as customers leaving after a certain number of rotations.

How GhostInterview Helps

  • GhostInterview offers guidance through step-by-step simulation strategies, ensuring you understand each rotation's impact on profit.
  • GhostInterview helps identify common pitfalls, such as overlooking gondola capacity or ignoring non-positive profit scenarios.
  • With detailed problem breakdowns, GhostInterview assists in calculating maximum profit and optimizing the number of rotations.

Topic Pages

FAQ

How does simulation apply to the Maximum Profit of Operating a Centennial Wheel problem?

Simulation is used to track customer arrivals, boarding, and profit after each rotation, making it essential to calculating the highest possible profit.

What’s the key challenge when solving the Maximum Profit of Operating a Centennial Wheel problem?

The challenge lies in determining the optimal stopping point and balancing customer arrivals with gondola capacity to maximize profit.

How do you handle multiple customers waiting to board the gondola in this problem?

Only four customers can board at each rotation, so the remaining customers must wait for the next rotation, which impacts profit calculations.

What happens if the profit is always negative in the Centennial Wheel problem?

If the profit remains negative after all rotations, the correct return value is -1, indicating no positive profit could be achieved.

Can the Maximum Profit of Operating a Centennial Wheel problem be optimized further?

While the current approach is efficient, further optimizations might include reducing unnecessary calculations or exploring alternative boarding strategies.

GhostInterview Solver

Need direct help with Maximum Profit of Operating a Centennial Wheel instead of spending more time grinding it?

Download GhostInterview when you want a LeetCode solver, not another long practice loop. Capture Maximum Profit of Operating a Centennial Wheel from a screenshot, get the answer path and complexity, and use supported stealth workflows that stay outside captured layers.

Screenshot Input

Capture the prompt fast instead of rewriting the problem by hand.

Answer + Complexity

Get the solution path, trade-offs, and complexity summary in one pass.

Stealth Workflow

Stay outside captured layers on supported screen-share workflows.