Maximum Profit of Operating a Centennial Wheel — LeetCode 1599 Python Solution

MediumArraySimulation
Problem
#1599
Reading time
4 min

The 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.

Example

Input
customers = [8,3], boardingCost = 5, runningCost = 6
Output
3
Explanation
The numbers written on the gondolas are the number of people currently there.

Python solution

Python
class Solution:
    def minOperationsMaxProfit(
        self, customers: List[int], boardingCost: int, runningCost: int
    ) -> int:
        ans = -1
        mx = t = 0
        wait = 0
        i = 0
        while wait or i < len(customers):
            wait += customers[i] if i < len(customers) else 0
            up = wait if wait < 4 else 4
            wait -= up
            t += up * boardingCost - runningCost
            i += 1
            if t > mx:
                mx = t
                ans = i
        return ans

Complexity

MeasureComplexity
TimeO(n), where n is the length of the `customers` array
SpaceO(1) auxiliary

Related problems

Frequently asked questions

How hard is LeetCode 1599. Maximum Profit of Operating a Centennial Wheel?
LeetCode 1599. Maximum Profit of Operating a Centennial Wheel is rated Medium on LeetCode.
What is the time complexity of LeetCode 1599. Maximum Profit of Operating a Centennial Wheel?
The Python solution on this page runs in O(n), where n is the length of the `customers` array.
What is the space complexity of LeetCode 1599. Maximum Profit of Operating a Centennial Wheel?
The Python solution on this page uses O(1) auxiliary space.
What topics does LeetCode 1599. Maximum Profit of Operating a Centennial Wheel cover?
LeetCode 1599. Maximum Profit of Operating a Centennial Wheel is tagged Array and Simulation on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview