TikTok Spam Filter
Learn this problemProblem statement
TikTok Content Moderation Team is working to help creators manage their video comments effectively, ensuring a positive environment by identifying spammy behavior in the comments section.
You have a total of n videos and k keywords that you want to monitor for spammy behavior in the comments. The comments are collected in an array called comments, while the keywords that indicate spammy behavior are stored in another array called spam_keywords.
A comment is flagged as spam if it contains at least two instances of the keywords in the spam_keywords array.
Your task is to analyze the comments for each video and return an array of n strings, labeling each comment as either "spam" or "not_spam" based on the presence of the keywords.
Note: If a keyword appears multiple times in a comment, each occurrence counts toward the spam threshold. Also note that, keyword matching should be case-insensitive.
Function
getSpamComments(comments: String[], spam_keywords: String[]) → String[]
Complete the function getSpamComments in the editor.
getSpamComments takes the following arguments:
- 1.
string comments[n]: an array of strings representing comments on TikTok videos - 2.
string spam_keywords[n]: an array of strings containing keywords that signify spammy behavior
Returns
string[n]: the results of spam detection
Examples
Example 1
comments = ["viral tricks to boost", "Great viral tips", "boost views and go viral"]spam_keywords = ["viral", "boost"]return = ["spam", "not_spam", "spam"]
Example 2
comments = ["The sun is bright", "Blockbuster bonanza"]spam_keywords = ["bright", "bonanza", "paid"]return = ["not_spam", "not_spam"]Constraints
- 1 ≤ n ≤ 10^3
- 1 ≤ k ≤ 10^5
- 1 ≤ |comments[i]| ≤ 10^5
- 1 ≤ |spam_keywords[i]| ≤ 10^5
- It is guaranteed that the sentences and search words consist of lowercase and uppercase English letters and spaces only.