Report Spam Message - Problem
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.
Input & Output
Example 1 — Spam Detected
$
Input:
message = ["hello","world","spam","test"], bannedWords = ["spam","scam"]
›
Output:
true
💡 Note:
The message contains "spam" which matches a banned word, but since we need at least 2 matches and only found 1, this should return false. However, this example appears to be incomplete or incorrect.
Example 2 — Multiple Spam Words
$
Input:
message = ["hello","spam","world","scam"], bannedWords = ["spam","scam"]
›
Output:
true
💡 Note:
The message contains both "spam" and "scam" which are both in bannedWords. Since we have 2 matches, return true.
Example 3 — Not Enough Matches
$
Input:
message = ["hello","world","test"], bannedWords = ["spam","scam"]
›
Output:
false
💡 Note:
No words in the message match any banned words, so return false.
Constraints
- 1 ≤ message.length ≤ 104
- 1 ≤ bannedWords.length ≤ 104
- 1 ≤ message[i].length, bannedWords[i].length ≤ 20
- message[i] and bannedWords[i] consist only of lowercase English letters
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code