DIY: Most Common Word

Solve the interview question "Most Common Word" in this lesson.

Problem statement

In this challenge, you are given a paragraph and a list of banned words. Your task is to find the most frequent word in the paragraph that is not in the list of banned words. While searching for the most common word, ignore the case and punctuation in the paragraph.

Note: It is guaranteed that the answer is unique, and there is at least one word that isn’t banned.


The inputs are a string named paragraph and a list of strings named banned. The words in banned are in lowercase, and the paragraph string is not case sensitive. The following is an example of the inputs:

paragraph = "Do not enter the forest. THE forest is haunted. The kids play in the FOREST and get haunted by witches."
banned = ["the", "do", "not", "in", "is"]


The output will be the string that is most common in the paragraph and does not belong in banned words. The output string should be in the lowercase.


Level up your interview prep. Join Educative to access 70+ hands-on prep courses.