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
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
1D dynamic programming
word break
string hashing
back pointers
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported