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.
I don't like this logic because it assumes that if there's a mistake in the charged value creating a debt it will only ever be because of the one excluded item and never any other value, meaning it constrains the possible values of b - which is correct given the story and test cases, but not as robust as:
debt = b - (sum(bill) - bill[k]) // 2
print(debt if debt else "Bon Appetit")
This always uses b in the response so it will work for all b in the constraints.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Bill Division
You are viewing a single comment's thread. Return to all comments →
I don't like this logic because it assumes that if there's a mistake in the charged value creating a debt it will only ever be because of the one excluded item and never any other value, meaning it constrains the possible values of b - which is correct given the story and test cases, but not as robust as:
This always uses b in the response so it will work for all b in the constraints.