Given a dictionary of root words and a sentence, replace each word in the sentence with its shortest root (if one exists). Example: dictionary = ["cat", "bat", "rat"], sentence = "the cattle was rattled by the battery" Output: "the cat was rat by the bat" "cattle" → "cat" (shortest root prefix) "rattled" → "rat" "battery" → "bat" Constraints: dictionary has up to roots, sentence has up to words.
Data Structures19 sections · 729 units
Open in CourseProblem - Replace Words
Trie for dictionary lookup