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 Description
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
Example 1:
Input: comments = ["viral tricks to boost", "Great viral tips", "boost views and go viral"], spam_keywords = ["viral", "boost"]
Output: ["spam", "not_spam", "spam"]
Explanation:Hence the answer is ["spam", "not_spam", "spam"].
Example 2:
Input: comments = ["The sun is bright", "Blockbuster bonanza"], spam_keywords = ["bright", "bonanza", "paid"]
Output: ["not_spam", "not_spam"]
Explanation:The first comment contains only one spam_keyword "bright". The second comment also contains only a single spam_keyword "bonanza". Since both these comments contains only 1 spam_keyword therefore both are flagged as "not_spam". Hence the answer is ["not_spam", "not_spam"].
- 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.

input:
output: