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.
- Prepare
- Algorithms
- Implementation
- Bill Division
- Discussions
Bill Division
Bill Division
+ 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 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 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 comments Python 3 codedef 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 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)))
Load more conversations
Sort 1548 Discussions, By:
Please Login in order to post a comment