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 Maximum Profit INPUT Boarding Point customers array: 8 1 [0] [1] board=5 running=6 Max 4 per gondola Profit = board - run ALGORITHM STEPS 1 Rotation 1 8 arrive, board 4, wait=4 Profit: 4*5-6 = 14 2 Rotation 2 1 arrive, board 4, wait=1 Profit: 14+14 = 28 3 Rotation 3 Board last 1, wait=0 Profit: 28+5-6 = 27 4 Track Maximum Max profit at rotation 2 maxProfit = 28 Simulation Summary Rot Board Wait Profit 1 4 4 14 2 4 1 28 MAX 3 1 0 27 Stop: profit drops FINAL RESULT 1 2 3 OUTPUT 3 3 rotations needed All 9 customers served Max profit = $28 OK - Positive profit! Key Insight: Simulate each rotation: track waiting customers (max 4 board per turn), accumulate profit (boardings*boardingCost - runningCost). Record rotation number when profit is maximum. Continue until no waiting customers. Return -1 if max profit never positive. TutorialsPoint - Maximum Profit of Operating a Centennial Wheel | Single Pass Simulation Approach
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