Find Hashtags Built Entirely From Other Hashtags in the List

Last updated: November 29, 2026

Quick Overview

Given a list of distinct hashtag strings, return every hashtag that can be written as a concatenation of at least two other (shorter) hashtags from the same list, where pieces may repeat.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given a list of distinct hashtag strings, return every hashtag that can be written as a concatenation of at least two other (shorter) hashtags from the same list, where pieces may repeat.

Instagram search splits compound hashtags like #summervibes into known parts, which motivates this concatenated-words problem. Interviewers want a word-break dynamic program that reuses already-processed shorter words, plus a clear argument about why sorting by length is enough.

What the Interviewer Expects
  • Sort by length so only shorter words can be pieces
  • Run a word-break DP per word against the set of shorter words
  • Require at least two pieces, so a word cannot match itself
  • Skip the empty string
  • Discuss a trie-driven DFS as an alternative
Key Topics to Cover
dynamic programming
word break
hash set
trie
sorting
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 return the actual split for each compound tag?
  • How would you count the number of distinct ways to split?
  • What if pieces may not repeat?
  • How would you scale to 10 million 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
  • Input: distinct lowercase strings, possibly including "".
  • Output: the compound hashtags, any order.
  • A compound must use at least two pieces, and every piece must be another word in the list (p...
High-Level Design

Process words from shortest to longest, keeping a set known of words seen so far. Any piece of a compound must be strictly shorter than it, so by the time we reach a word, all candidate pieces are i...


Submit Your Answer
Markdown supported