• + 0 comments

    java(8)

    public static void bonAppetit(List<Integer> bill, int k, int b) {
        // Write your code here
        int billAnna = 0;
        int billSum = 0;
        for (int i : bill) {
            billSum += i;
        }
    
        int billSplit = billSum / 2;
    
        if (billSplit == b) {
            for (int i = 0; i < bill.size(); i++) {
                if (i == k) {
                    continue;
                }
                billAnna += bill.get(i);
    
            }
    
            System.out.println((b - (billAnna / 2)));
        } else {
            System.out.println("Bon Appetit");
        }
    
    }