Segment a Run-Together Bing Query Into Dictionary Words
Last updated: November 29, 2026
Quick Overview
Bing receives queries typed without spaces, such as 'azurestoragepricing'. Given a vocabulary, return one way to split the query into vocabulary words, or None if no split exists.
Microsoft
November 29, 20260
0
0 solved
Bing receives queries typed without spaces, such as 'azurestoragepricing'. Given a vocabulary, return one way to split the query into vocabulary words, or None if no split exists.
A word-break variant tied to Bing query understanding. Interviewers look for DP over prefixes, a bound on word length to keep the inner loop short, and the ability to reconstruct the split rather than return a boolean.
What the Interviewer Expects
- Define ok[i] as whether the first i characters can be segmented
- Use a set for O(1) word lookups
- Bound the inner loop by the maximum word length
- Store back pointers to rebuild the segmentation
- Explain why plain recursion without memoization is exponential
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
- Return all possible segmentations. What is the worst-case output size?
- Prefer the segmentation with the fewest words, or the highest total word frequency.
- How would a trie speed up the inner loop?
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: query string and a list of vocabulary words.
- Output: list of words in order whose concatenation equals the query, or None.
- Any valid segmentation is acceptable....
High-Level Design
Let ok[i] be True when query[:i] can be fully split. ok[0] is True. For each end i, try every start j within max_len characters: if ok[j] and query[j:i] is a word, mark ok[i] and rem...