


Paragraph = ‘It's a square SqUare. It's a FLAT flat.’
Banned =[FLAT, IT, S].
So we can see these words [IT, S, SQUARE, FLAT ] are most frequent.
Now we will look at to banned list and we can see 3 of the words are banned.
So we have a unique answer SQUARE which has a frequency of 2 and not on the banned list.
The first line of input contains a string PARAGRAPH.
The second line of input contains an integer 'N' representing the size of the banned words list.
The third line of input contains 'N' space-separated words BANNEDWORDS.
Print the word (in UPPERCASE) which is most frequent and is not present in the list of banned words.
You don’t have to print anything. It has already been taken care of. Just implement the given function.
1<= N <=10^6
1<=banned.size<=100
Where ‘N’ is the size of paragraph.
Time limit: 1 second
First of all, we need to extract all words into an array of strings. We can do this the same way as we did in the earlier approach. But this time we will use Hashmap to store the frequency of each word and a Set to store the banned words so that we can check if the word is banned or not in constant time.
We can solve this problem without extracting words into extra space and without storing Banned into Set. We will only be using a Hashmap to store the frequency of words and will initialize the Banned words with a minimum value of INTEGER say INT_MIN. And from the given constraint we know once initialized with INT_MIN Banned words frequency can never reach a positive value. And the algorithm for processing words is given below: