Amazon Review Score π
Learn this problemProblem statement
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 prohibited words, ignoring case. A string contains a prohibited word if it has a contiguous substring that matches a word from the prohibited list, ignoring case.
Given a review and a list of prohibited words, calculate the review score.
Function
amazonReviewScore(review: String, prohibitedWords: String[]) β intComplete the function amazonReviewScore in the editor.
amazonReviewScore has the following parameters:
review: a stringprohibitedWords[n]: the prohibited words
Returns
int: the score of the review
Examples
Example 1
review = "GoodProductButScrapAfterWash"prohibitedWords = ["crap", "odpro"]return = 15Matching is case-insensitive. The prohibited words are "crap" and "odpro".
The substring "dProductButScra" does not contain either prohibited word and has length 15. Any longer substring would contain either "odpro" or "crap". Therefore the score is 15.
Example 2
review = "FastDeliveryOkayProduct"prohibitedWords = ["eryoka", "yo", "eli"]return = 11
Example 3
review = "ExtremeValueForMoney"prohibitedWords = ["tuper", "douche"]return = 20Constraints
1 <= |review| <= 1051 <= n <= 101 <= |prohibitedWords[i]| <= 10review consists of English letters, both lowercase and uppercaseprohibitedWords[i] consists of lowercase English letters
More Amazon problems
- Drone Delivery RouteOA Β· Seen Aug 2026
- Package Dependency OrderPHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Aug 2026
- Unfulfilled Customers by Inventory PriorityOA Β· Seen Aug 2026
- Calculate Beauty ValuesOA Β· Seen Aug 2026
- Maximize Distance to the Closest Occupied SeatONSITE INTERVIEW Β· Seen Aug 2026
- Package Delivery SystemOA Β· Seen Aug 2026
- Select Least Resource TasksOA Β· Seen Aug 2026
- Maximum Length-K Window Sum over Sparse SegmentsOA Β· Seen Aug 2026