Salesforce Online Assessment (OA) Experience 2024
Question Details
Problem 1: Spam Classification System
Problem Statement Implement a function to evaluate a list of texts and determine if they are "spam" or "not_spam." A text is classified as spam if it cont
Full Details
Problem 1: Spam Classification System
Problem Statement Implement a function to evaluate a list of texts and determine if they are "spam" or "not_spam." A text is classified as spam if it contains at least two occurrences of spam words from a provided list.
Rules *
Threshold: A text is "spam" if the total count of spam words detected is $\ge 2$. *
Counting: Each occurrence counts (e.g., if a spam word appears twice, it contributes 2 to the count). *
Matching: Matching is case-sensitive.
Function Signature
cpp vector<string> classifyTexts(vector<string> texts, vector<string> spamWords);
Example Input:
cpp texts = { "This is a limited offer just for you", // Contains "offer" (1) -> not_spam "Win cash now! Click here to claim your prize", // Contains "cash", "Click", "prize" (3) -> spam "Hello friend, just checking in", // Contains none (0) -> not_spam "Congratulations! You have won a free gift" // Contains "Congratulations", "free" (2) -> spam }; spamWords = {"offer", "cash", "Click", "prize", "Congratulations", "free"};
Output:
cpp ["not_spam", "spam", "not_spam", "spam"]
Constraints * $1 \le \text{number of texts} \le 10^3$ * $1 \le \text{number of spam words} \le 10^5$ * $1 \le \text{text length} \le 10^5$ * Combined length of all spam words $\le 10^7$
Solution Approach 1.
Preprocessing: Insert all spamWords into a HashSet for $O(1)$ average time complexity lookups. 2.
Evaluation: Iterate through each string in texts. 3.
Tokenization: Parse the current text into words/tokens (handling punctuation as delimiters). 4.
Counting: For each token in the text, check if it exists in the spamWords set. Maintain a running counter. 5.
Classification: If the counter reaches 2, mark as "spam." Otherwise, mark as "not_spam." ---
Problem 2: Delete and Earn
Problem Statement Given an integer array nums, maximize the number of points you can earn by applying the following operation any number of times: * Pick any nums[i] and delete it to earn nums[i] points. * After earning, you must delete every element equal to nums[i] - 1 and every element equal to nums[i] + 1.
Solution Approach This problem is a variation of the "House Robber" dynamic programming problem. 1.
Data Transformation: Convert the input array nums into a frequency map or a sum array. Let points[x] be the total value obtained by taking all occurrences of number x (calculated as x * count(x)). 2.
DP State: Let dp[i] be the maximum points earned considering numbers from $0$ to $i$. 3.
Recurrence Relation: For a number $i$, you have two choices: *
Skip $i$: Take the max points from the previous step: dp[i-1]. *
Take $i$: Add points[i] to the max points from i-2 (since taking $i$ deletes $i-1$): points[i] + dp[i-2]. * Formula: dp[i] = max(dp[i-1], dp[i-2] + points[i]). 4.
Result: The final answer is the value at the last index of the DP array.
About This Question
This is a reported interview question from a salesforce interview for a swe role during the oa round reported in 2025.
It covers the following topics: Hash Table, Arrays, Strings, Dynamic Programming, Ml .