Given a string paragraph and a string array of the banned words banned, return the most frequent word that is not banned. It is guaranteed there is at least one word that is not banned, and that the answer is unique.

The words in paragraph are case-insensitive and the answer should be returned in lowercase.

&nbsp;
Example 1:

Input: paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.", banned = ["hit"]
Output: "ball"
Explanation: 
"hit" occurs 3 times, but it is a banned word.
"ball" occurs twice (and no other word does), so it is the most frequent non-banned word in the paragraph. 
Note that words in the paragraph are not case sensitive,
that punctuation is ignored (even if adjacent to words, such as "ball,"), 
and that "hit" isn't the answer even though it occurs more because it is banned.


Example 2:

Input: paragraph = "a.", banned = []
Output: "a"


&nbsp;
Constraints:


	1 &lt;= paragraph.length &lt;= 1000
	paragraph consists of English letters, space ' ', or one of the symbols: "!?',;.".
	0 &lt;= banned.length &lt;= 100
	1 &lt;= banned[i].length &lt;= 10
	banned[i] consists of only lowercase English letters.


class Solution:
    import string
    from collections import Counter
    def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
        #sunday morning hangover solution haha
        
        #calling this twice seems unnecesary but whatevs
        #replace "," with " " (apparently translate() is much quicker than replace)
        para = paragraph.translate(str.maketrans(","," "))
        #strip out rest of punctuation and make it lower case
        para = para.translate(str.maketrans(' ', ' ', string.punctuation)).lower()
        #split on the sapces
        para = para.split()
        #staple counter function
        para_count = Counter(para)
        #loop thru banned words, if they're in para_count pop the off
        for word in banned:
            if word in para_count:
                para_count.pop(word)
        #return val from most common
        return para_count.most_common(1)[0][0]
class Solution {
    public String mostCommonWord(String paragraph, String[] banned) {

        HashMap<String, Integer> hm = new HashMap<>();
        String[] words = paragraph.replaceAll("[!?',;.]"," ").toLowerCase().split("\\s+");
        for(int i=0; i<words.length; i++)
        {
            if(hm.containsKey(words[i]))
                hm.replace(words[i], hm.get(words[i]), hm.get(words[i])+1);
            else
                hm.put(words[i], 1);
        }

        for(int i=0; i< banned.length; i++)
            if(hm.containsKey(banned[i]))
                 hm.remove(banned[i]);

        return Collections.max(hm.entrySet(), Map.Entry.comparingByValue()).getKey();
    }
}
class Solution {
public:
    string mostCommonWord(string paragraph, vector<string>& banned) {
        string temp;
        vector<string> words;
        for(char c:paragraph){
            if(isalpha(c) && !isspace(c)) temp+=tolower(c);
            else{
                if(temp.length()) words.push_back(temp);
                temp="";
            }
        }
        if(temp.length()) words.push_back(temp);
        
        map<string,int> mp;
        for(string i:words) mp[i]++;
        for(string i:banned) mp[i]=0;
        string ans;
        int maxUsedFreq=0;
        for(auto i:mp){
            if(i.second>maxUsedFreq){ 
                ans=i.first;
                maxUsedFreq=i.second;
            }
        }
        return ans;
    }
};
var mostCommonWord = function(paragraph, banned) {
	paragraph = new Map(Object.entries(
	paragraph
		.toLowerCase()
		.match(/\b[a-z]+\b/gi)
		.reduce((acc, cur) => ((acc[cur] = (acc[cur] || 0) + 1), acc), {}))
		.sort((a, b) => b[1] - a[1])
	);
	for (let i = 0; i < banned.length; i++) paragraph.delete(banned[i]);
	return paragraph.entries().next().value[0];
};
Most Common Word