Reported August 2023
Amazonstring

Amazon Review Score

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

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

Amazon's August 2023 OA included a problem asking you to find the longest contiguous substring of a review that doesn't contain any prohibited words. You're given a review string and a list of banned words, and you need to return the length of the clean substring. This is a string scanning problem with a hash-table lookup twist. If you blank on the algorithm during the live assessment, StealthCoder can surface the pattern in seconds.

The problem

Amazon allows customers to add reviews for the products they bought from their store. The review must follow Amazon's community guidelines in order to be published. Suppose that Amazon has marked n strings that are prohibited in reviews. They assign a score to each review that denotes how well it follows the guidelines. The score of a review is defined as the longest contiguous substring of the review which does not contain any string among the list of words from the prohibited list, ignoring the case. Given a review and a list of prohibited string, calculate the review score. Function Description Complete the function findReviewScore in the editor. findReviewScore has the following parameters: Returns int: the score of the review

Reported by candidates. Source: FastPrep

Pattern and pitfall

The core trick is treating this like a sliding window where you scan left to right, checking if any prohibited word starts at each position. For each index, you try to extend as far as possible without hitting a banned word. Most candidates overcomplicate by trying regex or brute-force substring matching. The efficient path: iterate through the review, and at each position, check if a prohibited word begins there (case-insensitive). When you hit one, reset your window and track the maximum length seen. A hash-table for O(1) word lookup speeds this up. Edge cases: overlapping prohibited words, case sensitivity, and empty windows. StealthCoder handles the lookup logic if you freeze on the matching step.

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 Amazon Review Score 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

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as longest substring without repeating characters. If you have time before the OA, drill that.

⏵ The honest play

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

Amazon 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.

Amazon Review Score FAQ

What's the trick to avoid timeout on long reviews?+

Don't check every possible substring. Instead, iterate once through the review and at each position, check only if a prohibited word starts there. Use a hash-table (set or dict) for O(1) word lookup. Track the longest gap between prohibited words.

Does case sensitivity matter here?+

Yes. The problem says 'ignoring the case,' so convert both the review and prohibited words to the same case (lowercase) before comparing. This is a common gotcha.

How do I handle overlapping or nested prohibited words?+

When you find a prohibited word starting at position i, move your window reset to the position after that word ends. Don't worry about shorter prohibited words inside it; you already found the violation.

Is this still a common Amazon pattern in 2024?+

String scanning and hash-table lookups appear frequently in Amazon OAs. This specific variant tests both pattern-matching and window tracking, so it's representative of their style.

Can I solve this in one pass?+

Yes. Iterate through the review once, maintain a start index for your current clean window, and when you hit a prohibited word, update your max length and reset the start. O(n*m) worst case, where m is the number of prohibited words.

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

OA at Amazon?
Invisible during screen share
Get it