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.

LinkedIn
Coding & Algorithms
Machine Learning Engineer
LinkedIn
November 29, 2026
Machine Learning Engineer
Onsite
Coding & Algorithms
Hard

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
dynamic programming
memoization
backtracking
text segmentation
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 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 Problems
Sample 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'...


Submit Your Answer
Markdown supported