Trains the technique from
LeetCode 322Coin 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 toll booth accepts plastic tokens. The integer array values lists the token types the booth recognises, where each entry is the credit one token of that type carries, and the booth's dispenser holds an unlimited number of tokens of every listed type.
A driver owes charge credits and the booth gives no change, so the tokens dropped in must add up to charge exactly. Return the smallest number of tokens that does it. If no combination of the listed types adds up to charge, return -1.
A charge of 0 credits is settled by dropping in nothing at all, so the answer there is 0.
Example 1
Two 4-credit tokens settle the charge. Reaching for the 6 first would force two 1s after it, which costs three tokens.
Example 2
Every token carries more credit than the charge, and the booth gives no change, so the charge cannot be settled.
Example 3
Nothing is owed, so no token is needed.
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 fewest_tokens(values: list[int], charge: int) -> int:public int fewestTokens(int[] values, int charge)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.