Ad
  • Default User Avatar

    You're correct - the solution only works with these specific bills as they are multiples of 25. The problem you mention is tougher. It's a good observation and something for me to think about. Thanks!

  • Default User Avatar

    Except that it's not a general algorithm. It still needs extra logic. Consider another situation where the ticket price in $20 and we have bills worth 10, 20, 50, and 100. When giving change for $100, one solution is to give back 4 $20 bills. But this algorithm can miss such a solution by giving $50 first and then realizing it doesn't have enough $10 bills to complete the transaction.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Brilliant! I love how you simply implemented a general algorithm for calculating the change rather than having a specialised case for every situation (paying with 25, 50 or 100 bill) as 99.9% of the solutions do.