Sort by

recency

|

1782 Discussions

|

  • + 0 comments

    Java 8

    public static void bonAppetit(List bill, int k, int b) { // Write your code here

        int totalCost = bill.stream().mapToInt(Integer::intValue).sum();
        int splitCharge = (totalCost - bill.get(k)) / 2;
        if(b - splitCharge > 0){
            System.out.println(b - splitCharge);
        } else{
            System.out.println("Bon Appetit");
        }
    
    }
    
  • + 0 comments

    Here is my c++ solution you can find the video here : https://youtu.be/MHFroRIBGQc

    void bonAppetit(vector<int> bill, int k, int b) {
        int s = accumulate(bill.begin(), bill.end(), -1 * bill[k]);
        int c = s / 2;
        if(c == b) cout << "Bon Appetit";
        else cout << b - c;
    }
    
  • + 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");
        }
    
    }
    
  • + 1 comment
    def bonAppetit(bill, k, b):
        am = (sum(bill) - bill[k])/2
        if(b>am):
            bal = b - am
            print(int(bal))
        else:
            print("Bon Appetit")
    
  • + 0 comments
    def bonAppetit(bill, k, b):
        bill[k]=0
        annabill=sum(bill)//2
        if annabill==b:
            print('Bon Appetit')
        else:
            print(b-annabill)