Detect Blocked Chat Messages
Problem statement
Given a finite ordered batch of chat messages and a list of blockedWords, return one boolean per message indicating whether it contains a blocked word.
For this exercise:
- A word is a maximal consecutive run of English letters
A-Zora-z. Every other character separates words. - Compare words without letter case. Blocked words are supplied in lowercase.
- A complete word must match; a blocked word inside a longer word does not count.
- Messages are independent, and a word cannot span messages.
- An empty message or an empty blocked-word list never produces a match. Repeated blocked words have no additional effect.
Function
detectBlockedMessages(messages: String[], blockedWords: String[]) → boolean[]Examples
Example 1
messages = ["A SPOILER!","spoilers ahead","normal chat"]blockedWords = ["spoiler"]return = [true,false,false]Matching ignores English letter case and requires the entire token: spoilers does not equal spoiler.
Example 2
messages = ["spam2offer","offer_spam",""]blockedWords = ["spam"]return = [true,true,false]Digits and underscores separate tokens. An empty message contains no token.
Example 3
messages = ["hello","HELLO"]blockedWords = []return = [false,false]An empty blocked-word list flags nothing.
Constraints
- For this exercise, assume
0 <= messages.length, blockedWords.length <= 100. - Each message has at most
1000printable ASCII characters. - Each blocked word has
1to20lowercase English letters.