Code Room
CodingHardcod-g455
Subject TokenizationLevel Senior–Staff~40 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.