Baseline Greedy Approach · Easy O(n) · O(1)
A kiosk sells single-entry passes for one base unit, and customers arrive in a fixed order paying with unit, double, or quadruple notes. The kiosk opens with an empty float and must hand exact change every time — a double customer gets one unit back, a quadruple customer gets three units back in whatever combination the float allows. Determine whether every customer can be served.
Input: An integer array bills of 5s, 10s and 20s in arrival order.
Output: Return true if change can be provided to every customer, false otherwise.
1 <= bills.length <= 10^5bills[i] is 5, 10 or 20Input: {"bills":[5,5,5,10,20]}
Output: true
Three 5s bank enough change: the 10 takes one 5, the 20 takes a 10 and a 5.
Input: {"bills":[5,5,10,10,20]}
Output: false
The final 20 arrives with no 5s left to combine with the 10.