Interview Question – 12 – Bon Appétit

By | November 15, 2018

Question

You can download the problem statement from here.

Solution

 static void bonAppetit(List<Integer> bill, int k, int charged) {
	    	
    int actualBill = 0;
    int payBill = 0;
    int size = bill.size();
    for(int i = 0; i < size; i++) {
        actualBill += bill.get(i);
    }
        
    payBill = actualBill - bill.get(k);
    payBill = payBill/2;
    
    print("Actual Bill : " + payBill);
    if(payBill == charged) {
        System.out.println("Bon Appetit");
    }else {
        System.out.println(Math.abs(charged - payBill));
    }

}

Leave a Reply

Your email address will not be published. Required fields are marked *