FastPrepFastPrep
Problem Brief

Amazon Review Score πŸ…

FULLTIMEOA
See Amazon online assessment and 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 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:

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

  • int: the score of the review
  • 1Example 1

    Input
    review = "GoodProductButScrapAfterWash", prohibitedWords = ["crap", "odpro"]
    Output
    15
    Explanation
    Some of the substrings that do not contain a prohibited word are: - ProductBut - rapAfterWash - dProductButScu - Wash The longest substring is "dProductButScra", return its length, 15.

    2Example 2

    Input
    review = "FastDeliveryOkayProduct", prohibitedWords = ["eryoka", "yo", "eli"]
    Output
    11
    Explanation
    Example 2 illustration
    The substring "OkayProduct" is the longest substring which does not contain a prohibited word. Its length is 11.

    3Example 3

    Input
    review = "ExtremeValueForMoney", prohibitedWords = ["tuper", "douche"]
    Output
    20
    Explanation
    The review does not contain any prohibited word, so the longest substring is "ExtremeValueForMoney", length 20.

    Constraints

    Limits and guarantees your solution can rely on.

  • 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
  • public int amazonReviewScore(String review, String[] prohibitedWords) {
      // write your code here
    }
    
    Input

    review

    "GoodProductButScrapAfterWash"

    prohibitedWords

    ["crap", "odpro"]

    Output

    15

    Sign in to submit your solution.