809. Stickers to Spell Word (Recursive + Memo)

HardRecursionRecursion

Given an array of sticker strings and a target string, return the minimum number of stickers needed so that their combined letters cover all letters of target. Each sticker can be used unlimited times. Return -1 if impossible. Input: JSON {stickers, target}.

Input: JSON {stickers, target}.

Output: Integer or -1.

Examples

Example 1
Input: {"stickers":["with","example","science"],"target":"thehat"}
Output: 3
Explanation: Use 'with' (for t,h), 'example' (for e,a), 'with' again (for t,h) — or other combos totaling 3.
Example 2
Input: {"stickers":["a","b","c"],"target":"abc"}
Output: 3
Explanation: One of each.

Constraints

Asked by

MetaGoogle
Solve this problem in the editor →