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.