Return every complete segmentation into valid syllables
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Overview: Enumerate all complete syllable segmentations of an unseparated lowercase string. Preserve the empty-input convention, deduplicate dictionary entries, order results canonically, and explain the output-sensitive cost of memoized suffix search.
Read the full Microsoft Software Engineer interview experience this question came from
Constraints
- `0 <= len(text) <= 30` and text contains only lowercase ASCII letters.
- There are between 0 and 1000 dictionary entries, each containing 1 through 10 lowercase ASCII letters.
- The total number of syllable occurrences across the returned segmentations is at most 100000.
Examples
Input: ('fangan', ['fan', 'gan', 'fang', 'an'])
Expected Output: [['fan', 'gan'], ['fang', 'an']]
Explanation: Both paths consume the full input and the shorter prefix comes first.
Input: ('abc', ['a', 'ab'])
Expected Output: []
Explanation: Every matching prefix leaves an impossible suffix.
Hints
- A prefix match can be valid locally while leaving an impossible suffix.
- Matching syllables that start at the same position can be compared by their lengths.