easy +10 pts

Lemonade Change

Determine if you can give correct change to every customer in line.

You are selling lemonade at a stand. Each lemonade costs $5. Customers line up to buy one lemonade each, paying with a $5, $10, or $20 bill. You must give each customer the correct change immediately after they pay, using only the bills you have received from previous customers. Write a function `lemonade_change(bills: list[int]) -> bool` that returns `True` if you can provide correct change to every customer in the order given by `bills`, and `False` otherwise. You start with no cash on hand.

Constraints

1 <= len(bills) <= 10^5 Each element in bills is one of 5, 10, or 20.

Example

>>> lemonade_change([5,5,5,10,20])
True
>>> lemonade_change([5,5,10,10,20])
False
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Track the number of $5 and $10 bills you have.
When a customer pays with $20, prefer using a $10 and a $5 for change.
If you ever cannot make exact change, return False immediately.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.