Skip to content
Decoder

Lemonade Change

Easy

Problem

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.

Example 1

Input
bills = [5, 5, 5, 10, 20]
Output
true

Example 2

Input
bills = [5, 5, 10, 10, 20]
Output
false
Why
the last customer needs $15 and you only hold two $10s

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.