Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
What B1ts says doesn't imply changing the order of the list.
There are two ways to give change for a $100 and one is more efficient than the other.
Vasya can successfully give change to everyone in this case without changing the order:
Then the Kata is not clear on that. It mentions nothing about being able to shuffle people around. When most people think a line, they think first to last, one after the other.
The clerk collects 25 (no change), then another 25, then he receives 50 and gives back 25 change. He now has 1 x 25 and 1 x 50 (exactly 75), which he gives to the next customer and keeps the 100.
Out of the two options you provided, #1 is correct.
Does that make sense now?
Okay.. so if I used that logic: how do i answer [25, 25, 50, 100] = true ?
To explain in detail, these were the two encounters I tried to go with:
e.g. Clerk has 50, customer gives 100: Clerk has enough change because (remainder of 50 + ticket of 25) = 75
e.g. Clerk has 50, customer gives 100: Clerk does not have enough of change because customer needs 75 and clerk CURRENTLY only has 50
No, he wouldn't have enough. The clerk would receive 1 x 100 bill, and he has only 2 x 25 bills to give for change (not enough for 75 needed)
"Should return false for {25, 25, 100}"
I don't quite get this, because the clerk would've had 50 by the time it reached the 3rd person in line. If the clerk sold a ticket to that person, the clerk would've had enough of change at 75 which is needed by the customer.
I used this logic because it applied to other test cases, or the other cases would've failed.
Not a kata issue.
Don't you think you could use that 50 to give change for 100? The test case is correct.
Test given: [25, 25, 25, 25, 50, 100, 50], to return True; However this is not the case because after accumulating the first four customer's money, the toal adds up to 100, leaving a 25 change for the next customer who pays 50, the total becomes 75; leaving a 75 change for the next customer who pays 100, the total becomes 0; the clerk does not have enough change for the next customer who pays 50.