Most Common Word

EasyStringshashing

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Given a text paragraph and a list of banned words, return the most frequently occurring word in paragraph that is not banned. Words are maximal runs of English letters; everything else (spaces and the punctuation symbols !?',;.) separates words. Matching is **case-insensitive**, and the word you return must be in **lowercase**. You are guaranteed that at least one non-banned word exists and that the most frequent non-banned word is unique. All entries of banned are lowercase.

Examples

Input: paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.", banned = ["hit"]
Output: "ball"
"hit" occurs 3 times but is banned; "ball" (counting "BALL") occurs twice, more than any other word.
Input: paragraph = "a.", banned = []
Output: "a"
The only word is "a".

Constraints

  • 1 <= paragraph.length <= 1000
  • `paragraph` contains English letters, spaces, and the symbols `!?',;.`
  • 0 <= banned.length <= 100
  • 1 <= banned[i].length <= 10
  • `banned[i]` consists of lowercase English letters

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More hashing problems