Trains the technique from
LeetCode 691Stickers to Spell WordThis 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.
There is an unlimited supply of every stencil in stencils, and each stencil is a word of lowercase letters. Letters may be cut out of a stencil and arranged in any order.
Spell the word target from cut-out letters, using as few stencils as possible. Letters that are not needed are simply left over.
Return the fewest stencils needed, or -1 when the target cannot be spelt at all.
Example 1
One stencil supplies a single a, so two of them are needed to spell two.
Example 2
Neither stencil holds all four letters, but one supplies the a and the other supplies the d, and between them the middle two are covered as well.
Example 3
The only stencil holds no b at all, so the target can never be spelt.
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 min_stickers(stencils: list[str], target: str) -> int:public int minStickers(String[] stencils, String target)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.