Code RoomMinimum cost word segmentation
MediumPrep Room Coding #1376

Minimum cost word segmentation

CodingAlgorithms & data structuresMid–Senior~30 min

Given a lowercase string s and a dictionary of (word, cost) pairs, segment s into a sequence of dictionary words minimizing the total cost (each used word contributes its cost; a word may be used multiple times). Return the minimum total cost, or -1 if s cannot be segmented. Words can repeat in the input only once each. Length of s up to ~1000.

Implement
min_cost_word_break(s: str, words: list[list]) → int
Examples
in["notebook",[["note",3],["book",4],["notebook",10]]]out7
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 30 min
InputExpectedGot
["notebook",[["note",3],["book",4],["notebook",10]]]7not run yetsample