Spam Detection
Updated
Problem statement
You are given an array of email subjects and an array of spam_words. Classify each subject as spam or not_spam.
- Split a subject into words separated by spaces. Leading, trailing, and repeated spaces do not form words.
- A subject word matches a spam word only when the complete words are equal, ignoring uppercase and lowercase differences. A substring does not count.
- Count matching occurrences in the subject. Repeated occurrences of the same spam word count separately.
- A subject is spam when it contains at least two matching occurrences. Otherwise, it is not spam.
Each vocabulary entry is a single nonempty English word. Repeated vocabulary entries, including entries that differ only in case, do not increase the count for a subject occurrence.
Return an array containing one classification for each subject, in the original order.
Function
getSpamEmails(subjects: String[], spam_words: String[]) → String[]Examples
Example 1
subjects = ["free prize worth millions","ten tips for a carefree lifestyle"]spam_words = ["free","money","win","millions"]return = ["spam","not_spam"]The first subject contains free and millions. In the second subject, carefree does not match the complete word free.
Example 2
subjects = ["WIN win","win","winner"]spam_words = ["win","WIN"]return = ["spam","not_spam","not_spam"]The first subject has two matching occurrences of the same word. The repeated vocabulary entry does not make the single occurrence in the second subject count twice. The last subject has no whole-word match.
Example 3
subjects = [" free FREE ","free zero","zero"]spam_words = ["Free"]return = ["spam","not_spam","not_spam"]Spaces are separators, not words. Ignoring case, the subjects contain two, one, and zero matching occurrences.
Constraints
1 <= subjects.length <= 10^31 <= spam_words.length <= 10^51 <= subjects[i].length <= 10^51 <= spam_words[i].length <= 10^5- Subjects contain English letters and spaces. Each spam word contains only English letters. Both uppercase and lowercase letters are allowed.
- The combined length of all subjects and vocabulary entries is at most
2 * 10^5characters.
More Vanguard Online Assessment questions
- Two SumOA · Seen Sep 2026
- Valid ParenthesesOA · Seen Sep 2026
- Are They PangramsOA · Seen Nov 2025
- Missing WordsOA · Seen Nov 2025
- Binge WatchingOA · Seen Jan 2023
- Minimum Moves Around a Circular ArrayOA · Seen Aug 2022
- Maximum Occurring CharacterOA · Seen Mar 2022
- Picking TicketsOA · Seen Mar 2022
- Tool List: Two Smallest ValuesOA · Seen Nov 2021
- Group AnagramsOA · Seen Nov 2019
Similar questions at other companies
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- First Non-Repeating CharacterAmazon · OA · ONSITE INTERVIEW
- Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- Count Palindrome Addition ChoicesThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Count Palindrome Addition ChoicesHudson River Trading · OAHudson River Trading interview questions
- Count Phrases Formed by Anagram ReplacementWells Fargo · OAWells Fargo interview questions
- Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
- Branch with the Most FilesCapital One · OACapital One interview questions