A pop-up stand's point-of-sale app sells one item for 5 dollars. Customers pay in order, each with a single 5, 10, or 20 dollar bill, listed in bills. The register starts empty and must give each customer exact change from the bills it has collected so far.
Write canMakeChange(bills) that returns true if every customer gets correct change, and false otherwise.
Input: bills = [5,5,5,10,20] Output: true
The 10 gets a 5 back, and the 20 gets a 10 and a 5 back.
Input: bills = [5,5,10,10,20] Output: false
The last customer needs 15 back, but the register only holds two 10s.
0 <= bills.length <= 1000005, 10, or 20.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #572 Make Change at a Pop-Up Stand. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.