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.

Be the first one to answer
Add answer anonymously...
Standard Chartered Full Stack 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