Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Lemonade Change

Easy
greedysimulation

Customers queue to buy $5 lemonade, paying with $5, $10, or $20 bills. You start with no change. Return true if you can give every customer correct change, processing them in order.

Input: one line of space-separated bills (each 5, 10, or 20). Output: true or false.

Example 1
Input:
5 5 5 10 20
Output:
true
Example 2
Input:
5 5 10 10 20
Output:
false

Constraints

  • 1 ≤ bills.length ≤ 10^5
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.