We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Bill Division
  5. Discussions

Bill Division

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 1548 Discussions, By:

recency

Please Login in order to post a comment

  • eze_moro
    4 days ago+ 0 comments

    C#

    int fairlyValue = (bill.Sum() - bill[k])/2;
    int toBeRefund = b - fairlyValue;
    
    if(toBeRefund == 0)
     Console.Write("Bon Appetit");
    else
     Console.Write(toBeRefund);
    
    0|
    Permalink
  • junivensaavedra
    5 days ago+ 0 comments

    Here's my short and sweet python solution. Enjoy. :)

    def bonAppetit(bill, k, b):
        # Write your code here
        eaten: int = (sum(bill) - bill[k]) // 2
        print("Bon Appetit" if eaten == b else f"{b - eaten}")
    
    0|
    Permalink
  • malmar1701
    6 days ago+ 0 comments

    JavaScript

    function bonAppetit(bill, k, b) {
      bill.splice(k, 1);
      let billSum = bill.reduce((acc, curValue) => acc + curValue, 0) / 2;
      let toBeRefund = b - billSum;
    
      return console.log(billSum === b ? "Bon Appetit" : toBeRefund);
    }
    }
    
    0|
    Permalink
  • idttalbe_m
    1 week ago+ 0 comments
    Python 3 code
    def bonAppetit(bill:list, k, b):
        # Write your code here
        new_bill = bill.copy()
        new_bill.pop(k)
        price = sum(new_bill)/2
        if price == b:
            print('Bon Appetit')
        else:
            print('%d' %(b - price))
    
    0|
    Permalink
  • Traininghard
    2 weeks ago+ 0 comments

    Python3

    def bonAppetit(bill, k, b):
        # Write your code here
        diff = (sum(bill)-bill[k])/2
        if diff == b:
            print('Bon Appetit')
        else:
            print(abs(int(diff-b)))
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy