Maximum Profit of Operating a Centennial Wheel - 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.

You are given an array customers of length n where customers[i] is the number of new customers arriving just before the i-th rotation (0-indexed). This means you must rotate the wheel i times before the customers[i] customers arrive. You cannot make customers wait if there is room in the gondola. Each customer pays boardingCost dollars when they board on the gondola closest to the ground and will exit once that gondola reaches the ground again.

You can stop the wheel at any time, including before serving all customers. If you decide to stop serving customers, all subsequent rotations are free in order to get all the customers down safely. Note that if there are currently more than four customers waiting at the wheel, only four will board the gondola, and the rest will wait for the next rotation.

Return the minimum number of rotations you need to perform to maximize your profit. If there is no scenario where the profit is positive, return -1.

Input & Output

Example 1 — Basic Case
$ Input: customers = [8,1], boardingCost = 5, runningCost = 6
Output: 3
💡 Note: Rotation 0: 4 customers board (4 wait), profit = 4*5-6 = 14. Rotation 1: 1+4=5 customers, 4 board (1 wait), profit = 14+4*5-6 = 28. Rotation 2: 1 customer boards, profit = 28+1*5-6 = 27. Rotation 3: 0 customers board, profit = 27+0*5-6 = 21. Maximum profit is 28 at rotation 1, but we need 3 more rotations for customers to exit, so return 3.
Example 2 — No Profit
$ Input: customers = [10,9,6], boardingCost = 6, runningCost = 4
Output: 7
💡 Note: Each rotation can board max 4 customers earning 4*6=24, but costs 4, so net +20 per full rotation. Process all customers and additional rotations to maximize profit.
Example 3 — Unprofitable
$ Input: customers = [3,4,0,5,1], boardingCost = 1, runningCost = 92
Output: -1
💡 Note: Maximum revenue per rotation is 4*1=4, but cost is 92, so every rotation loses money. No positive profit possible.

Constraints

  • 1 ≤ customers.length ≤ 1000
  • 0 ≤ customers[i] ≤ 50
  • 1 ≤ boardingCost, runningCost ≤ 100

Visualization

Tap to expand
Centennial Wheel: Maximize Profit from OperationsWheel4 gondolascustomers = [8,1]8 then 1 arriveProfit CalculationRevenue: customers × $5Cost: $6 per rotationMax 4 customers/rotationRotation Profits:R0: 4×$5-$6 = $14R1: 5×$5-$6 = $19 → $33R2: 1×$5-$6 = -$1 → $32R3: 0×$5-$6 = -$6 → $26Max at rotation 1But need R3 to emptyOutput: 3Stop after rotation 3Simulate each rotation to find maximum profit point
Understanding the Visualization
1
Input
customers=[8,1], boardingCost=5, runningCost=6
2
Simulate
Track profit at each rotation as customers board
3
Output
Return rotation number with maximum profit
Key Takeaway
🎯 Key Insight: Simulate the wheel operation step by step, tracking the maximum profit achieved at any rotation
Asked in
Google 25 Facebook 18
23.4K Views
Medium Frequency
~25 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen