Most Frequent Non-Banned Word Problem Statement

Given a paragraph consisting of letters in both lowercase and uppercase, spaces, and punctuation, along with a list of banned words, your task is to find the most frequent word that is not in the list of banned words. The solution will always exist and be unique.

While considering words, treat letters as case-insensitive (e.g., 'AsK' and 'aSK' are the same). Words consist solely of alphabets, separated by spaces or punctuation, and the result should be returned in uppercase.

Example:

Input:
Paragraph = "It's a square SqUare. It's a FLAT flat."
N = 3
BANNEDWORDS = [ "FLAT", "IT", "S" ]
Output:
SQUARE
Explanation:

The most frequent words (case-insensitive) are [IT, S, SQUARE, FLAT], each appearing twice. After checking with the banned list, 'SQUARE' remains as the most frequent word not banned, with a frequency of 2.

Constraints:

  • 1 <= N <= 106 (where N is the size of the paragraph)
  • 1 <= banned.size <= 100
  • Time limit: 1 second

Note:

You do not need to output anything as it's handled elsewhere. Your task is to implement the given function.

AnswerBot
14h

Find the most frequent word in a paragraph that is not in a list of banned words.

  • Split the paragraph into words and convert them to uppercase for case-insensitivity.

  • Count the frequency of each word, e...read more

Janavi Paratane
4mo
Steps: Normalize the Input: Convert all the words in the paragraph to lowercase to avoid case-sensitivity issues. Remove punctuation like commas, periods, etc., so that only the words remain. Split th...read more
Help your peers!
Add answer anonymously...
Josh Technology Group Web Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter