Given a string paragraph and a string array of banned words, return the most frequent word in the paragraph that is not banned. It is guaranteed that at least one word is not banned and that the answer is unique. Words are case-insensitive, punctuation separates words, and the answer must be returned in lowercase.
Given a string paragraph and a string array of banned words, return the most frequent word in the paragraph that is not banned. It is guaranteed that at least one word is not banned and that the answer is unique. Words are case-insensitive, punctuation separates words, and the answer must be returned in lowercase.
Example 1:
Input: {"paragraph":"Bob hit a ball, the hit BALL flew far after it was hit.","banned":["hit"]}
Output: ball
Constraints:
1≤paragraph.length≤1000
paragraph consists of English letters, space, and the symbols !?',;.
0≤banned.length≤100
1≤banned[i].length≤10
banned[i] consists of only lowercase English letters.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"paragraph":"Bob hit a ball, the hit BALL flew far after it was hit.","banned":["hit"]}
Put the 1 banned word into a set so each check is O(1).