Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyClass {
- public static void main(String args[]) {
- int seatPrices[][] = { {-1,42,13,17,23},
- {11,13,-1,10,10},
- {14,12,15,-1,-1},
- {16,17,10,11,19},
- {-1,-1,-1,-1,-1},
- {-1,14,17,-1,14},
- };
- int seatCombo = 0;
- int totalPrice = -1;
- int requiredSeats = 3;
- int rowNumber = 0;
- int lowestComboPrice = -1;
- int comboCount = 0;
- int firstPrice = 0;
- //iterate over entire plane
- for(int i=0; i<seatPrices.length; i++) {
- //reset for new row
- System.out.println("total Price reset for new row ");
- seatCombo = 0;
- totalPrice = 0;
- // Iterate over row
- for(int j=0; j<seatPrices[i].length; j++) {
- rowNumber = i;
- System.out.println("seat location = [" + i + "][" + j + "]");
- //iterate over each seat
- if(seatPrices[i][j] != -1) {
- System.out.println("added seat at [" + i + "][" + j + "]");
- seatCombo ++;
- totalPrice += seatPrices[i][j];
- if(seatCombo == 1) {
- firstPrice = seatPrices[i][j];
- }
- if(seatCombo == requiredSeats) {
- System.out.println("Combo limit hit at = [" + i + "][" + j + "]");
- System.out.println("total Price = " + totalPrice);
- if (comboCount == 0) {
- lowestComboPrice = totalPrice;
- comboCount++;
- } else {
- if(totalPrice < lowestComboPrice) {
- lowestComboPrice = totalPrice;
- }
- }
- seatCombo --;
- totalPrice -= firstPrice;
- System.out.println("Price decremented due to completion, totalPrice = " + totalPrice);
- }
- } else {
- seatCombo = 0;
- totalPrice = 0;
- System.out.println("combo borked, total price = " + totalPrice);
- }
- //System.out.println("Seat price at arr["+i+"]["+j+"] is "+seatPrices[i][j]);
- }
- }
- System.out.println("lowest total Price = " + lowestComboPrice);
- return ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement