Pack Sticker Tags Into the Shortest Hash-Terminated Index String

Last updated: November 29, 2026

Quick Overview

Given a list of sticker tags, build the shortest reference string made of tags each followed by '#' such that every tag appears as a substring that ends right before some '#'. Return only its length.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a list of sticker tags, build the shortest reference string made of tags each followed by '#' such that every tag appears as a substring that ends right before some '#'. Return only its length.

This tests whether a candidate sees that a tag can share storage only when it is a suffix of another tag. Meta interviewers expect a reversed-trie or suffix-removal solution and a short proof of why that is optimal.

What the Interviewer Expects
  • Notice that tag t is free when it is a suffix of another tag
  • Use a trie of reversed tags and count leaves
  • Add depth plus one for each leaf to account for '#'
  • Deduplicate repeated tags
  • Compare with the set-based suffix-removal approach
Key Topics to Cover
reversed trie
suffix sharing
hash set
string encoding
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you output the reference string and each tag's offset?
  • What if tags could also overlap at the start (prefix sharing)?
  • How does this relate to suffix trees?
  • How would memory change for very long tags?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Tags are lowercase, length up to 7, up to 2,000 tags, duplicates possible.
  • A tag is encoded by an index into the string; reading from that index up to the next # must give the tag.
  • Return the ...
High-Level Design

Each # ends one stored chunk, and a tag can be read from a chunk only if it is a suffix of that chunk. So a tag that is a suffix of another tag needs no chunk of its own, and a tag that is not a...


Submit Your Answer
Markdown supported