Replace Words
easy
1. You r given an array of string's say dictionary and a long string say sentence. 2. You have to replace all words in sentence which contains a prefix in dictionary with the prefix itself in dictionary. Example dictionary = ["cat","bat","rat"] sentence = "the cattle was rattled by the battery" In this sentence cattle, rattled and battery are the words containing prefix in dictionary they are cat, rat and bat. sentence after replace words is "the cat was rat by the bat". 3. If there are multiple prefix for a word in dictionary replace it with the shortest prefix word.
Constraints
1. 1 <= dictionary.length <= 1000 2. 1 <= dictionary[i].length <= 100 3. 1 <= sentence.length <= 10^6 4. dictionary[i] an sentence consists of only lower-case letters.
Format
Input
Input is managed for you
Output
Output is managed for you
Example
Sample Input
4
catt
cat
bat
rat
the cattle was rattled by the battery
Sample Output
the cat was rat by the bat