Maximum Profit of Operating a Centennial Wheel - Problem
Maximum Profit of Operating a Centennial Wheel
You're the operator of a Centennial Wheel (a large ferris wheel) with 4 gondolas, where each gondola can hold up to 4 customers. The wheel rotates counterclockwise, and each rotation costs you
Given an array
Key Rules:
• You must rotate i times before
• Maximum 4 customers can board per rotation (excess customers wait)
• You can stop operating at any time
• After stopping, remaining rotations to bring customers down are free
Goal: Return the minimum rotations needed to achieve maximum profit, or
You're the operator of a Centennial Wheel (a large ferris wheel) with 4 gondolas, where each gondola can hold up to 4 customers. The wheel rotates counterclockwise, and each rotation costs you
runningCost dollars.Given an array
customers where customers[i] represents new customers arriving just before the i-th rotation, you must decide the optimal number of rotations to maximize profit. Each customer pays boardingCost when boarding and exits when their gondola returns to the ground.Key Rules:
• You must rotate i times before
customers[i] arrive• Maximum 4 customers can board per rotation (excess customers wait)
• You can stop operating at any time
• After stopping, remaining rotations to bring customers down are free
Goal: Return the minimum rotations needed to achieve maximum profit, or
-1 if no positive profit is possible. Input & Output
example_1.py — Basic Case
$
Input:
customers = [8,3], boardingCost = 5, runningCost = 6
›
Output:
3
💡 Note:
Rotation 1: 4 customers board (4 waiting), profit = 4×5 - 1×6 = 14. Rotation 2: 4 more customers board (3 still waiting), profit = 8×5 - 2×6 = 28. Rotation 3: 3 remaining customers board, profit = 11×5 - 3×6 = 37. This is the maximum profit achievable.
example_2.py — Unprofitable Case
$
Input:
customers = [10,9,6], boardingCost = 6, runningCost = 4
›
Output:
7
💡 Note:
Even though there are many customers, we need to find the optimal stopping point. After serving all customers across multiple rotations, rotation 7 gives the maximum profit.
example_3.py — No Profit Case
$
Input:
customers = [3,4,0,5,1], boardingCost = 1, runningCost = 92
›
Output:
-1
💡 Note:
Since the running cost (92) is much higher than the maximum possible revenue per rotation (4×1=4), it's impossible to make a profit regardless of how many customers we serve.
Constraints
- n == customers.length
- 1 ≤ n ≤ 105
- 0 ≤ customers[i] ≤ 50
- 1 ≤ boardingCost, runningCost ≤ 100
- Each gondola holds exactly 4 customers
- Customers must be served in arrival order
Visualization
Tap to expand
Understanding the Visualization
1
Customers Arrive
New customers join the waiting queue before each rotation
2
Board & Rotate
Up to 4 customers board, wheel rotates (costs money)
3
Calculate Profit
Revenue from boarding minus rotation costs
4
Track Maximum
Remember the best profit and when it occurred
5
Optimal Stop
Return the rotation count that maximized profit
Key Takeaway
🎯 Key Insight: Single-pass simulation with profit tracking eliminates the need for multiple expensive simulations, achieving optimal O(n) time complexity.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code