Problem · String
Spam Classification
Learn this problemProblem statement
For MTS role.
You are given a list of texts and a list of spam words. Classify each text as "spam" if it contains at least 2 spam words, and "not spam" otherwise. Spam words and texts are case-insensitive.
Approach "I" used: Converted spamWords to lowercase and stored in a HashSet. Iterated through each text, split it into words, normalized them to lowercase, and counted how many match spam words. Marked it as "spam" if the count was 2 or more.
Edge Case: Spam words can repeat, and each occurrence must be counted.
Function
classifyTexts(texts: String[], spamWords: String[]) → String[]Examples
Example 1
texts = ["Free prize worth millions", "Ten tips for a carefree lifestyle"]spamWords = ["free", "money", "win", "millions"]return = ["spam", "not_spam"]:)