Sort by

recency

|

1780 Discussions

|

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

  • + 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

    Solution in Java

    public static void bonAppetit(List<Integer> bill, int k, int b) {
            int share = 0;
            for(int i = 0; i < bill.size(); i++){
                if(i != k){
                    share += bill.get(i);
                }
            }
            if((share / 2) == b){
                System.out.println("Bon Appetit");
            }
            else{
                System.out.println(b - share / 2);
            }
        }