Reported September 2022
ZipRecruiterhash table

Classify Reviews by Sentiment Word Occurrences

Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ZipRecruiter OA. Under 2s to a working solution.
Founder's read

The whole problem hinges on one hash set, and ZipRecruiter put it in front of candidates in September 2022. You get a list of reviews and two word lists. For each review, count positive and negative token hits, then label it positive, negative, or neutral. It looks like string handling, and it is. But the real work is deciding how to look words up fast. If you've got this OA coming, the pattern is simple and the traps are small. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but you shouldn't need it for this one.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Build two hash sets, one from positiveWords and one from negativeWords. Then loop over each review, split on whitespace, and check each token against both sets. Increment the positive counter if the token is in the positive set. Increment the negative counter if it's in the negative set. Those are two separate checks, not an if/else, because a token in both lexicons counts for both. Compare the counters at the end and append positive, negative, or neutral. The common pitfalls are using else-if, lowercasing tokens, stripping punctuation, and deduplicating repeated words. The spec says matching is case-sensitive, punctuation stays attached, and repeats count every time. Total work is linear in the input text length, which is capped at 200000, so nothing fancy is needed. Handle empty reviews and an empty reviews array by returning an empty list. If you freeze during the live OA, StealthCoder gives you this exact set-and-counter structure as a hedge.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Classify Reviews by Sentiment Word Occurrences cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass ZipRecruiter's OA.

ZipRecruiter reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Classify Reviews by Sentiment Word Occurrences FAQ

What's the trick in the ZipRecruiter review sentiment problem?+

Put both word lists into hash sets so each token lookup is constant time. Then count hits per review and compare. The trick is really about not over-processing: no lowercasing, no punctuation stripping, no deduplication. Follow the spec literally and it works.

What happens when a word is in both positive and negative lists?+

It counts toward both totals. Use two independent if checks, not if/else. If a review is just that one word, both counts are 1 and the result is neutral. This is the easiest place to lose a hidden test.

Do repeated words count more than once?+

Yes. Every occurrence adds to the count, so 'good good bad' has 2 positive and 1 negative. Don't convert the review into a set of unique tokens. Iterate over the raw split tokens and increment per match.

How hard is this problem really?+

Easy. It's a straightforward string split plus set lookup, and time is linear in total text length. The difficulty is only in reading carefully: case-sensitive matching, punctuation staying in tokens, and the dual-lexicon rule. Most failures are misreads, not algorithm gaps.

How do I prepare for this in 48 hours?+

Write it once from scratch in your language of choice. Test the three examples plus an empty reviews array, an empty review string, a token like 'good!' that shouldn't match 'good', and a word in both lists. Check how your language splits on multiple spaces. That covers nearly everything.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ZipRecruiter.

OA at ZipRecruiter?
Invisible during screen share
Get it