Created
September 27, 2020 11:14
-
-
Save jonathanagustin/690dcda425f7793b8dc66c0d49584024 to your computer and use it in GitHub Desktop.
1599. Maximum Profit of Operating a Centennial Wheel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int: | |
| CAPACITY = 4 | |
| NO_PROFIT = -1 | |
| numCustomersWaiting = 0 | |
| totalCustomers = 0 | |
| currentProfit = NO_PROFIT | |
| previousProfit = NO_PROFIT | |
| maxProfit = NO_PROFIT | |
| numRotations = 0 | |
| minRotationsForMaxProfit = NO_PROFIT | |
| while customers or numCustomersWaiting: | |
| # GET THE NEXT GROUP OF CUSTOMERS | |
| currentNumCustomers = customers.pop(0) if customers else 0 | |
| # ADD TO TOTAL NUMBER OF CUSTOMERS WAITING | |
| numCustomersWaiting += currentNumCustomers | |
| # BOARD THE NEXT GROUP, 4 IS THE CAPACITY | |
| numCustomersBoarding = min(numCustomersWaiting, CAPACITY) | |
| # REMOVE BOARDING GROUP FROM NUMBER OF CUSTOMERS WAITING | |
| numCustomersWaiting = numCustomersWaiting - numCustomersBoarding | |
| # KEEP TOTAL COUNT OF CUSTOMERS TO CALCULATE PROFIT | |
| totalCustomers += numCustomersBoarding | |
| # ROTATE THE CENTENNIAL WHEEL | |
| numRotations += 1 | |
| # CALCULATE CURRENT PROFIT | |
| currentProfit = (totalCustomers * boardingCost) - (numRotations * runningCost) | |
| # MAINTAIN HIGHEST PROFIT NUMBER FOR RETURN | |
| if 0 < currentProfit > maxProfit: | |
| maxProfit = currentProfit | |
| minRotationsForMaxProfit = numRotations | |
| # SET UP FOR NEXT ITERATION | |
| previousProfit = currentProfit | |
| return minRotationsForMaxProfit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment