Sort by

recency

|

1797 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

    Here's my PHP solution:

    function bonAppetit($bill, $k, $b) {
        // Write your code here
        unset($bill[$k]);
        $fairAmount = array_sum($bill)/2;
        $remaining = $b - $fairAmount;
    
        echo $remaining ?: 'Bon Appetit';
    }
    
  • + 0 comments
    def bonAppetit(bill, k, b):
        
        # Write your code here
        
        value = bill.pop(k)
        
        actual = sum(bill)//2
        
        if actual == b:
            print('Bon Appetit')
            
        else:
            diff = b - actual
            
            print(diff)
    
  • + 0 comments

    C# solution

    public static void bonAppetit(List<int> bill, int k, int b)
        {
            bill.RemoveAt(k);
            int realBill = (bill.Sum())/2;
            
            Console.WriteLine((realBill == b) ? "Bon Appetit" : b-realBill);
        }
    
  • + 0 comments

    Kotlin:

    var actualAmount=0
            bill.forEachIndexed { i,it ->
                if(i!=k) actualAmount+=it
            }
            val actualSplitAmount=actualAmount/2
            if(b==actualSplitAmount){
                println("Bon Appetit")
            }else{
                val overchargedAmount=b-actualSplitAmount
                println(overchargedAmount)
            }