Split Concatenated Hashtags Into All Valid Word Sequences
Last updated: November 29, 2026
Quick Overview
Given a lowercase hashtag with no spaces (like 'opentowork') and a dictionary of words, return every way to split it into a space-separated sequence of dictionary words.
0
0
0 solved
Given a lowercase hashtag with no spaces (like 'opentowork') and a dictionary of words, return every way to split it into a space-separated sequence of dictionary words.
Hashtag segmentation feeds LinkedIn's content understanding and topic tagging. The interviewer checks memoized DFS over suffixes, awareness that the output itself can be exponential, and a cheap feasibility check before enumerating.
What the Interviewer Expects
- Starts from the boolean word break DP to test feasibility
- Uses memoization keyed by start index to avoid recomputation
- Bounds candidate word lengths by the longest dictionary word
- Explains that output can be exponential, so complexity is output-sensitive
- Discusses ranking splits by word frequency for production
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return only the most likely split using unigram probabilities?
- How do you handle a word not in the dictionary, such as a brand name?
- How would you segment millions of hashtags in a batch job efficiently?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: string s up to a few hundred characters and a list of words. Output: list of all sentences (words joined by single spaces) in any order. If no split exists, return []. Dictionary words can be...
High-Level Design
Two steps. First, a quick boolean DP from the right: ok[i] is True if s[i:] can be fully split. This prunes dead branches, which matters for adversarial input like 'aaaa...ab' with words 'a', 'aa'...