Ctrl K

Spam Word Alarm

Medium
A message is given as an array of words words, and the list banned holds forbidden words. The message counts as **spam** when at least two of its words (two positions in the array) exactly match some word in banned. The same banned word showing up twice also counts as two matches. Return True if the message is spam and False otherwise.
Example 1
words=['win', 'a', 'free', 'cruise'], banned=['free', 'win', 'prize'] → True

The message holds two banned words, "win" and "free", so it is spam.

Example 2
words=['see', 'you', 'at', 'lunch'], banned=['lunch', 'prize'] → False

Only one banned word, "lunch", appears, which is not enough.

Example 3
words=['cash', 'now', 'cash'], banned=['cash'] → True

Words of the message are counted, not distinct banned words: "cash" appears twice, so the message is spam.

Constraints
  • 1 ≤ len(words), len(banned) ≤ 10⁵
  • 1 ≤ length of every word ≤ 15
  • All words consist of lowercase English letters only
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAnagram Buckets MediumSplit Into Dictionary Words MediumWords Equal Up to a Shift MediumA Subsequence of One Word Only MediumFiles With the Same Content Medium
loading Python…
Input
words=['win', 'a', 'free', 'cruise'], banned=['free', 'win', 'prize']
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 96 tests on the server, hidden ones included.