Trains the technique from
LeetCode 139Word BreakThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A firmware build stamps each module with a short lowercase code, and the label of an assembled unit is the codes of its modules written one after another with nothing in between.
You are given a label label and a catalogue codes of the codes in use, all distinct. Decide whether label could have come off the line: is there a run of catalogue codes whose concatenation is exactly label, using every character of the label and adding none?
A code may be reused as often as needed, and the catalogue may contain codes that go unused. Return true if such a run exists and false otherwise.
Example 1
The label breaks into `port`, `map` and `per`, three catalogue codes in a row with nothing left over.
Example 2
`grid` is stamped twice, once at the front and once at the back, which is allowed because codes may repeat.
Example 3
`sun` and `flow` cover the first seven characters and leave `er`, which no code matches, and `power` never lines up anywhere in the label. No run of codes reproduces it.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def label_splits(label: str, codes: list[str]) -> bool:public boolean labelSplits(String label, List<String> codes)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.