Leetcode 1599: Maximum Profit of Operating a Centennial Wheel

grid47
grid47
Exploring patterns and algorithms
May 31, 2024 7 min read

You operate a giant Ferris wheel with four gondolas, each holding up to four passengers. The Ferris wheel rotates counterclockwise and incurs a running cost for every rotation. You are given a list of customer arrivals, where each entry indicates the number of customers arriving just before the ith rotation. Customers board the gondola closest to the ground, and only a maximum of four customers can board at any time, while any excess wait for the next rotation. Each customer pays a boarding cost. Your task is to determine the minimum number of rotations needed to achieve the maximum profit. If there is no scenario where the profit is positive, return -1.
Problem
Approach
Steps
Complexity
Input: An array of integers representing the number of customers arriving just before each rotation.
Example: [12, 4]
Constraints:
• 1 <= n <= 10^5
• 0 <= customers[i] <= 50
• 1 <= boardingCost, runningCost <= 100
Output: Return the minimum number of rotations to achieve the maximum profit. If no profit can be achieved, return -1.
Example: 3
Constraints:
• Return the minimum number of rotations to achieve the maximum profit.
• If no profit can be achieved, return -1.
Goal: Determine the minimum number of rotations to maximize profit.
Steps:
• Keep track of the number of waiting customers.
• For each rotation, add new customers and board the maximum number of customers (up to 4).
• Compute the profit after each rotation by subtracting the running cost from the boarding revenue.
• Stop when the profit is maximized and return the number of rotations required.
Goal: Ensure that the number of customers does not exceed the number of gondolas available. Running and boarding costs must be within the specified range.
Steps:
• n = length of the customers array
• 1 <= n <= 10^5
• 0 <= customers[i] <= 50
• 1 <= boardingCost, runningCost <= 100
Assumptions:
• At most four customers can board per rotation.
• The wheel rotates counterclockwise.
• Once the wheel stops, no additional rotations will be made.
Input: customers = [12, 4], boardingCost = 8, runningCost = 5
Explanation: After 3 rotations, the maximum profit of $84 is achieved. Thus, the answer is 3.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus