All problems
1190MediumArrayHash TableString

Two Barred Terms Hold the Ticket

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3295Report Spam Message

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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