Practice/Datadog/Leetcode 819. Most Common Word
CodingMust
You are given a text paragraph containing words separated by spaces and various punctuation marks. You are also given a list of banned words that should be ignored during analysis.
Your task is to find and return the most frequently occurring word in the paragraph that is not in the banned list. The comparison should be case-insensitive, and all punctuation should be removed when identifying words.
!?',;.Example 1:
Input: paragraph = "Apple! Apple? Banana.", banned = [] Output: "apple" Explanation: After normalization, "apple" appears 2 times and "banana" appears 1 time. Since no words are banned, "apple" is the most frequent word.
Example 2:
Input: paragraph = "a, a, a, a, b,b,b,c, c", banned = ["a"] Output: "b" Explanation: After normalization, "a" appears 4 times, "b" appears 3 times, and "c" appears 2 times. Since "a" is banned, "b" becomes the most frequent valid word.
Example 3:
Input: paragraph = "Hello world! Hello everyone.", banned = ["world"] Output: "hello" Explanation: "hello" appears 2 times, "world" appears 1 time (but is banned), and "everyone" appears 1 time. "hello" is the most frequent non-banned word.