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.
Examples
01 · Example 1
texts = ["Free prize worth millions", "Ten tips for a carefree lifestyle"] spamWords = ["free", "money", "win", "millions"] return = ["spam", "not_spam"]
:)
More Salesforce problems
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Key Teams in TreeOA · Seen Mar 2026
- System Energy ReductionOA · Seen Mar 2026
- Update Logs by Symmetric XOROA · Seen Mar 2026
- Count Palindromic Concatenation PairsOA · Seen Mar 2026
- Collect Opportunity Data in a TreeOA · Seen Feb 2026
- Replace '?' to Avoid Adjacent DuplicatesOA · Seen Feb 2026
public String[] classifyTexts(String[] texts, String[] spamWords) {
// write your code here
}
texts["Free prize worth millions", "Ten tips for a carefree lifestyle"]
spamWords["free", "money", "win", "millions"]
expected["spam", "not_spam"]
sign in to submit