Report Spam Message

You are given an array of strings message and an array of strings bannedWords.

An array of words is considered spam if there are at least two words in it that exactly match any word in bannedWords.

Return true if the array message is spam, and false otherwise.

Example 1
Inputmessage = ["hello","world","leetcode"], bannedWords = ["world","hello"]
Outputtrue
The words "hello" and "world" from the message array both appear in the bannedWords array.
Example 2
Inputmessage = ["hello","programming","fun"], bannedWords = ["world","programming","leetcode"]
Outputfalse
Only one word from the message array ("programming") appears in the bannedWords array.

Constraints

  • 1 <= message.length, bannedWords.length <= 10^5
  • 1 <= message[i].length, bannedWords[i].length <= 15
  • message[i] and bannedWords[i] consist only of lowercase English letters.

Asked at 2 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate