#691
Stickers to Spell Word
candidate master · 1410 · lc hard +32 · verified · 50.7% accepted · 1,334 likes · top 39%
Description
You have n types of stickers, each bearing a lowercase English word. By cutting individual letters from stickers and rearranging them, you want to spell out the string target. Each type of sticker can be used any number of times.
Return the minimum number of stickers needed to form target, or -1 if it is impossible.
Note: Words were randomly chosen from the 1000 most common US English words, and target is the concatenation of two such random words.
Example 1:
Input: stickers = ["with","example","science"], target = "thehat"
Output: 3
Explanation:
We can use 2 "with" stickers, and 1 "example" sticker.
After cutting and rearrange the letters of those stickers, we can form the target "thehat".
Also, this is the minimum number of stickers necessary to form the target string.
Example 2:
Input: stickers = ["notice","possible"], target = "basicbasic"
Output: -1
Explanation:
We cannot form the target "basicbasic" from cutting letters from the given stickers.
Code
1
2
3