Sort by

recency

|

1810 Discussions

|

  • + 0 comments

    rust

    fn bon_appetit(bill: &[i32], k: i32, b: i32) {
        let _k = k as usize;
        let out = match bill.iter()
            .enumerate()
            .filter_map(|(i, x)| if i != _k {Some(*x)} else {None})
            .sum::<i32>()
            .wrapping_div(2)
            .wrapping_sub(b)
            .abs() {
                0 => "Bon Appetit".to_string(),
                x => x.to_string()
            };
        println!("{out}")
    }
    
  • + 0 comments

    When splitting a bill, like Anna and Brian did, fairness means only paying for what you actually ate. If Anna skipped an item, that cost should be excluded before dividing the total. For example, if the meal included DQ burgers and fries but Anna passed on one burger, Brian should calculate her share based only on the items she consumed. If he overcharged her, the extra amount should be refunded. You can try this logic in real scenarios.

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

    When dividing bills among roommates or friends, clear communication is essential to avoid disputes. Use apps or spreadsheets to track expenses fairly. If a disagreement leads to debt collection or harassment, it's important to know your rights. Learn how to protect yourself from unfair practices by visiting ERS Resolution Group Debt Collection Harassment. Stay informed to handle billing issues responsibly.

  • + 0 comments

    python code with O(n) time and O(1) time:

    def bonAppetit(bill, k, b):
        total = sum(bill)
        anas_cost = total - bill[k]
        even_split = anas_cost / 2
        
        if even_split == b:
            print("Bon Appetit")
        else:
            print(math.floor(b - even_split))