Replace Words
mediumReplace words in a sentence by the shortest dictionary root
Replace Words
Key Insight
Insert all roots first, then for each sentence word return first prefix that is terminal in the trie.
Step 1Build Root Set
Array
cat
0bat
1rat
2HashMap
cat:3
bat:3
rat:3
Insert cat, bat, rat into trie.
1 / 3