Description
Given a string paragraph and a string array of banned words, return the most frequent word that is not banned. Words are case insensitive.
Examples
Input:
paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.", banned = ["hit"]Output:
"ball"Explanation:
ball appears 2 times.
Input:
paragraph = "The quick brown fox jumps over the lazy dog. The dog was very lazy!", banned = ["the", "was"]Output:
dogExplanation:
After removing banned words 'the' and 'was', and normalizing case/punctuation, 'dog' appears 2 times while other words appear only once.
Input:
paragraph = "Apple, apple! Orange orange? Apple.", banned = []Output:
appleExplanation:
With no banned words, all words are counted. 'Apple' appears 3 times (case-insensitive) while 'orange' appears 2 times, making 'apple' the most frequent.
Constraints
- •
1 ≤ paragraph.length ≤ 1000