You work as a clerk at a cinema box office and a new movie has been released. There are a lot of people standing in a line waiting to buy a ticket with either
100 dollar bill. Each ticket for the new movie costs
If you start with no money in the register, can you sell a ticket to every person in line and give change? You must attend to everyone in order, it would be unfair to sell tickets out of order.
YES, if you can sell a ticket to every person and give change.
tickets([25, 25, 50]) =>
tickets([25, 100]) =>
NO You will not have enough money to give change to 100 dollars
tickets([25, 25, 50, 50, 100]) =>
NO You will not have the right bills to give 75 dollars of change (you can't make two bills of 25 from one of 50)
tickets([25, 25, 50, 50])
tickets([25, 50, 25, 100])
Want to propose a challenge idea for a future post? Email firstname.lastname@example.org with your suggestions!