Problem · String

Spam Classification

EasySalesforceFULLTIMEOA
See Salesforce hiring insights

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
drafts saved locally
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