Dsa
Dynamic Programming
Easy
Rearrange Stickers to Form Words
You have a collection of stickers, each represented as a string. You can use stickers to form words. Each sticker can be used multiple times, but you want to determine if you can form a given target word using these stickers. Return the minimum number of stickers needed to form the target word, or -1 if it is not possible. For example, stickers = ['with', 'example', 'science'], target = 'thehat' requires 3 stickers.
Input Format:
- The first line contains an integer n (1 ≤ n ≤ 20), the number of stickers.
- The second line contains n space-separated strings, the stickers.
- The third line contains the target word.
Output Format:
- Output a single integer, the minimum number of stickers needed to form the target word.
Example:
Input:
3
with example science
thehat
Output:
3
Key concepts
dynamic_programmingcombinatoricsstring
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now