Classify Reviews by Sentiment Word Occurrences
Updated
Problem statement
For every review, split on whitespace and count all token occurrences found in positiveWords and negativeWords. Repeated tokens count repeatedly. Matching is case-sensitive and punctuation remains part of a token.
Return positive when the positive count is greater, negative when it is smaller, and neutral when the counts are equal. A token present in both lexicons contributes to both counts.
Function
classifyReviews(reviews: String[], positiveWords: String[], negativeWords: String[]) → String[]Examples
Example 1
reviews = ["good good bad","bad","plain"]positiveWords = ["good"]negativeWords = ["bad"]return = ["positive","negative","neutral"]The batch contains positive, negative, and neutral reviews.
Example 2
reviews = ["great great poor"]positiveWords = ["great"]negativeWords = ["poor"]return = ["positive"]Every matching occurrence contributes.
Constraints
0 <= reviews.length <= 10000- The total input text length is at most
200000.
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
Similar questions at other companies
- Branch with the Most FilesCapital One · OACapital One interview questions
- 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