Shorten words to their shortest root
You get a list roots and a sentence of words separated by single spaces. A word can be shortened to a root when it starts with that root; a word equal to a root counts. Replace every word that has at least one such root with the shortest of them, leave the other words unchanged, and return the new sentence.
Roots and words use lowercase a–z and have at least one letter. roots may be empty or contain repeats; the sentence has at least one word.
Besides the tests, one large input (8,000 roots, 5,000 words) with a ~400 ms limit (scaled to your device's speed): brute force won't pass.
Examples
shorten(["help","play","re"], "helpful players replayed the game")→"help play re the game"shorten(["sun","su","sunny"], "sunny sunday sugar sand")→"su su su sand"shorten(["x"], "plain words stay")→"plain words stay"