Show problems as
Classic problem #3295MediumArrayHash TableString

Report Spam Message

Real-world version: Two Barred Terms Hold the Ticket
Tracked in this browser only
Read Report Spam Message on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A support ticket reaches the desk as a list of lowercase words, words, and the desk keeps a list of barred terms, barred.

The desk holds the ticket back once two of its words match a barred term exactly. Those two can be the same term matched twice, since they are still two words of the ticket.

Return true when the ticket is held back and false when it goes through.

Examples

Example 1

Input
words = ["refund", "late", "lost"], barred = ["refund", "lost"]
Output
true

Two of the three words of the ticket are barred terms, so the desk holds it.

Example 2

Input
words = ["refund", "refund"], barred = ["refund"]
Output
true

One barred term, but the ticket carries it twice, and two words of the ticket are what the desk counts.

Example 3

Input
words = ["carpet", "car"], barred = ["car", "van"]
Output
false

Only the second word matches a barred term. The first merely contains one, which is not a match, so one word is all the desk has.

Constraints

  • 1 <= words.length <= 10^5
  • 1 <= barred.length <= 10^5
  • 1 <= words[i].length <= 15
  • 1 <= barred[i].length <= 15
  • words[i] and barred[i] hold lowercase English letters only

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def report_spam(words: list[str], barred: list[str]) -> bool:
Java
public boolean reportSpam(String[] words, String[] barred)