Spell a Target with the Fewest Reusable Stickers

Quick Overview

Find the minimum number of reusable word stickers needed to assemble a lowercase target when letters may be cut and rearranged. Account for repeated letters, unused sticker characters, impossible targets, and the empty target.

Spell a Target with the Fewest Reusable Stickers

Company: Bytedance

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Problem You have several sticker types. Each sticker is a lowercase word, and you may use any sticker type any number of times. Letters cut from one sticker can be rearranged. Return the minimum number of stickers needed to assemble the target string, or `-1` if the target cannot be assembled. ### Function Contract Implement `minStickers(stickers, target)`. ### Constraints & Assumptions - `1 <= len(stickers) <= 50`. - `1 <= len(stickers[i]) <= 10`. - `0 <= len(target) <= 15`. - All strings contain lowercase English letters. - Each physical sticker can contribute each printed letter at most once, but every sticker type is available without limit. - Return `0` for an empty target. ### Clarifying Questions to Ask - May letters be rearranged after cutting? Yes. - Are unused letters allowed? Yes. - Is each listed sticker available once? No, each type may be reused. - What if some target character appears on no sticker? Return `-1`. ```hint Use the uncovered target as state Represent which target positions have already been supplied with a bitmask, or represent the remaining letter counts canonically. ``` ```hint Reduce branching From a state, choose one uncovered target character and consider only stickers containing that character. ``` ### Example ```text stickers = ["with", "example", "science"] target = "thehat" output = 3 ``` Two copies of `"with"` and one copy of `"example"` can provide the required letters. ### Evaluation Focus - Accounts for repeated target letters and duplicate letters on a sticker. - Avoids enumerating assignments of sticker letters to equivalent target positions. - Detects impossible targets. - Uses memoization or breadth-first search over at most `2^len(target)` coverage states. ### Extensions to Discuss 1. How would preprocessing remove dominated stickers? 2. When is a remaining-count string state preferable to a position bitmask? 3. How would the problem change if each sticker type had a limited quantity?

Quick Answer: Find the minimum number of reusable word stickers needed to assemble a lowercase target when letters may be cut and rearranged. Account for repeated letters, unused sticker characters, impossible targets, and the empty target.

|Home/Coding & Algorithms/Bytedance
Bytedance logo
Bytedance
May 22, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0

Problem

You have several sticker types. Each sticker is a lowercase word, and you may use any sticker type any number of times. Letters cut from one sticker can be rearranged. Return the minimum number of stickers needed to assemble the target string, or -1 if the target cannot be assembled.

Function Contract

Implement minStickers(stickers, target).

Constraints & Assumptions

  • 1 <= len(stickers) <= 50 .
  • 1 <= len(stickers[i]) <= 10 .
  • 0 <= len(target) <= 15 .
  • All strings contain lowercase English letters.
  • Each physical sticker can contribute each printed letter at most once, but every sticker type is available without limit.
  • Return 0 for an empty target.

Clarifying Questions to Ask Guidance

  • May letters be rearranged after cutting? Yes.
  • Are unused letters allowed? Yes.
  • Is each listed sticker available once? No, each type may be reused.
  • What if some target character appears on no sticker? Return -1 .

Example

stickers = ["with", "example", "science"]
target = "thehat"
output = 3

Two copies of "with" and one copy of "example" can provide the required letters.

Evaluation Focus

  • Accounts for repeated target letters and duplicate letters on a sticker.
  • Avoids enumerating assignments of sticker letters to equivalent target positions.
  • Detects impossible targets.
  • Uses memoization or breadth-first search over at most 2^len(target) coverage states.

Extensions to Discuss

  1. How would preprocessing remove dominated stickers?
  2. When is a remaining-count string state preferable to a position bitmask?
  3. How would the problem change if each sticker type had a limited quantity?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...