Skip to content

Lemonade Change

EasyGreedy
Decode it first. Clues, constraints, pattern and plan before any code.

Lemonade costs $5. Customers pay in order, each with a single $5, $10 or $20 bill, given in bills. You start with no change at all. Return true if you can give every customer correct change.

bills = [5, 5, 5, 10, 20]   →  true
bills = [5, 5, 10, 10, 20]  →  false   (the last customer needs $15 and you only hold two $10s)

Constraints

  • 1 <= bills.length <= 10^5
  • bills[i] is 5, 10 or 20.