Trains the technique from
LeetCode 860Lemonade ChangeThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A left-luggage kiosk rents one locker per traveller at a flat 5 credits. Travellers reach
the counter in the order given by tokens, and tokens[i] is the single token the i-th
traveller hands over: worth 5, 10 or 20 credits.
The kiosk opens with an empty till. Whenever a traveller pays more than 5 credits, the kiosk must hand back the difference using whole tokens it already holds, and the only tokens it holds are the ones earlier travellers paid with. A traveller paying 10 needs 5 credits back, and a traveller paying 20 needs 15 credits back.
Return true if every traveller can be given exact change in this order, and false if
some traveller cannot.
Example 1
The fifth traveller is handed one 5 back. The sixth is handed a 10 and a 5, which is the 15 credits owed. The last two are each handed one 5 back, so nobody is short.
Example 2
When the third traveller pays 20, the till holds only two 5 tokens, which is 10 credits, so the 15 credits owed cannot be handed back.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def can_serve_all(tokens: list[int]) -> bool:public boolean canServeAll(int[] tokens)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.