Code RoomSmallest dictionary segmentation
HardPrep Room Coding #1024

Smallest dictionary segmentation

CodingAlgorithms & data structuresSenior–Staff~40 min

Segment a string with no spaces into a sequence of dictionary tokens. Given `s` and `words` (a list of allowed tokens), return the lexicographically SMALLEST valid tokenization as a list of tokens, where 'lexicographically smallest' compares the resulting list of tokens element by element (shorter list is NOT automatically smaller; standard Python list comparison of the token lists). If no segmentation exists, return an empty list. `s` is lowercase letters; `words` may contain duplicates; the empty string segments to [].

Implement
segment_min(s: str, words: list[str]) → list[str]
Examples
in["catsand",["cat","cats","and","sand"]]out["cat","sand"]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 40 min
InputExpectedGot
["catsand",["cat","cats","and","sand"]]["cat","sand"]not run yetsample