Report Spam Message
Real-world version: Two Barred Terms Hold the TicketThe 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.
def report_spam(words: list[str], barred: list[str]) -> bool:public boolean reportSpam(String[] words, String[] barred)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Verifying an Alien DictionaryReal-world version: Catalogue Order Under a Custom Glyph SequenceEasy
- Find Common CharactersReal-world version: Tiles Every Rack Can SupplyEasy
- Destination CityReal-world version: Last Stop On The Courier RunEasy
- Find Words That Can Be Formed by CharactersReal-world version: Signs Spellable From A Tile TrayEasy