Maximum Profit of Operating a Centennial Wheel LeetCode solution in Java
1class Solution {2public int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {3int rotatn = 0;4int cust = 0;5int profit = Integer.MIN_VALUE;6int prRotn = 0;7int cSit = 0;89for (int i = 0; i < customers.length; i++) {10cust += customers[i];11rotatn++;1213int prof = 0;14if (cust >= 4) {1516cust = cust - 4;17cSit += 4;18} else {19cSit += cust;20cust = 0;21}22prof = cSit * boardingCost - rotatn * runningCost;23if (prof > profit) {24profit = prof;25prRotn = rotatn;26}27}28while (cust > 0) {29rotatn++;3031int prof = 0;32if (cust >= 4) {33cust = cust - 4;34cSit += 4;35} else {36cSit += cust;37cust = 0;38}39prof = cSit * boardingCost - rotatn * runningCost;4041if (prof > profit) {42profit = prof;4344prRotn = rotatn;45}46}47if (profit > 0) return prRotn;48return -1;49}50}