Problem Β· String

Amazon Review Score πŸ…

● MediumAmazonFULLTIMEOA
See Amazon hiring insights

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 Description

Complete the function amazonReviewScore in the editor.

amazonReviewScore has the following parameters:

  • review: a string
  • prohibitedWords[n]: the prohibited words

Returns

  • int: the score of the review
Examples
01 Β· Example 1
review = "GoodProductButScrapAfterWash"
prohibitedWords = ["crap", "odpro"]
return = 15

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

02 Β· Example 2
review = "FastDeliveryOkayProduct"
prohibitedWords = ["eryoka", "yo", "eli"]
return = 11
Example 2 illustration
The substring "OkayProduct" is the longest substring which does not contain a prohibited word. Its length is 11.
03 Β· Example 3
review = "ExtremeValueForMoney"
prohibitedWords = ["tuper", "douche"]
return = 20
The review does not contain any prohibited word, so the longest substring is "ExtremeValueForMoney", length 20.
Constraints
  • 1 <= |review| <= 105
  • 1 <= n <= 10
  • 1 <= |prohibitedWords[i]| <= 10
  • review consists of English letters, both lowercase and uppercase
  • prohibitedWords[i] consists of lowercase English letters
More Amazon problems
drafts saved locally
public int amazonReviewScore(String review, String[] prohibitedWords) {
  // write your code here
}
review"GoodProductButScrapAfterWash"
prohibitedWords["crap", "odpro"]
expected15
checking account