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.
Input Format
Input is managed for you
Output Format
Output is managed for you
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.
Notice
Try First, Check Solution later
1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.3. We strongly advise you to watch the solution video for prescribed approach.Example
Input
4 catt cat bat rat the cattle was rattled by the battery
Output
the cat was rat by the bat