FastPrepSpam Text Classification
Problems/Spam Text Classification

Spam Text Classification

Salesforce logoSalesforceFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

A classification system evaluates whether each text is spam using a list of spam words.

A text is labeled "spam" if it contains at least two spam-word occurrences. Each occurrence of a spam word counts toward the total, and matching is case-sensitive.

Given an array texts and an array spamWords, return an array where each element is either "spam" or "not_spam" for the corresponding text.

Function

classifyTexts(texts: String[], spamWords: String[]) → String[]

Examples

Example 1

texts = ["This is a limited offer just for you","Win cash now! Click here to claim your prize","Hello friend, just checking in","Congratulations! You have won a free gift"]spamWords = ["offer","cash","Click","prize","Congratulations","free"]return = ["not_spam","spam","not_spam","spam"]

The first and third texts contain fewer than two spam-word occurrences. The second and fourth texts contain at least two.

Constraints

  • 1 <= texts.length <= 10^3
  • 1 <= spamWords.length <= 10^5
  • 1 <= text.length <= 10^5
  • 1 <= spamWord.length <= 10^5
  • The combined length of all spam words is at most 10^7.

More Salesforce Online Assessment questions

  • Count Subarrays With Product Equal to KOA · Seen Nov 2026
  • Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
  • Get Message StatusOA · Seen Nov 2026
  • Minimum Unique-Character Segments After DeletionOA · Seen Sep 2026
  • Run-Length String CompressionOA · Seen Sep 2026
  • Maximum Requests in WindowOA · Seen Sep 2026
  • Final Pod Counts After LogsOA · Seen Aug 2026
  • Minimum Removals to Balance ArrayOA · Seen Aug 2026
  • Is This Date a Weekend?OA · Seen Aug 2026
  • Maximum Barbell WeightOA · Seen Jul 2026

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public String[] classifyTexts(String[] texts, String[] spamWords) {
      // write your code here
    }
}
Checking account…