Sort by

recency

|

1781 Discussions

|

  • + 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)
    
  • + 0 comments

    def bonAppetit(bill, k, b): bill.pop(k) print('Bon Appetit' if sum(bill)//2 == b else b - sum(bill)//2)