Return every complete segmentation into valid syllables

Quick 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.

Return every complete segmentation into valid syllables

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

Given a lowercase string with no separators and a collection of valid syllables, return all complete segmentations of the string into those syllables. A syllable may be reused. Every character must belong to exactly one chosen syllable. ### Function Signature ```python def all_syllable_segmentations(text: str, syllables: list[str]) -> list[list[str]]: ``` ### Rules - Return each segmentation as its ordered list of syllables. - Return distinct segmentations in lexicographic order, comparing syllable strings and then list positions. - Duplicate dictionary entries do not create duplicate results. - Return `[]` if the input text is empty or no complete segmentation exists. ### Constraints These bounds define this practice version. - `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 ```text Input: text = "fangan", syllables = ["fan", "gan", "fang", "an"] Output: [["fan", "gan"], ["fang", "an"]] ``` Both outputs consume the full string. ```text Input: text = "abc", syllables = ["a", "ab"] Output: [] ``` No permitted syllable consumes the remaining suffix. ```text Input: text = "", syllables = ["a"] Output: [] ``` The external empty-input convention differs from the successful internal empty suffix used during recursion.

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

Microsoft logo
Microsoft
Dec 1, 2026
hardSoftware EngineerTechnical ScreenCoding & Algorithms
0
0

Given a lowercase string with no separators and a collection of valid syllables, return all complete segmentations of the string into those syllables. A syllable may be reused. Every character must belong to exactly one chosen syllable.

Function Signature

def all_syllable_segmentations(text: str, syllables: list[str]) -> list[list[str]]:

Rules

  • Return each segmentation as its ordered list of syllables.
  • Return distinct segmentations in lexicographic order, comparing syllable strings and then list positions.
  • Duplicate dictionary entries do not create duplicate results.
  • Return [] if the input text is empty or no complete segmentation exists.

Constraints

These bounds define this practice version.

  • 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: text = "fangan", syllables = ["fan", "gan", "fang", "an"]
Output: [["fan", "gan"], ["fang", "an"]]

Both outputs consume the full string.

Input: text = "abc", syllables = ["a", "ab"]
Output: []

No permitted syllable consumes the remaining suffix.

Input: text = "", syllables = ["a"]
Output: []

The external empty-input convention differs from the successful internal empty suffix used during recursion.