Description
Solutions
Calculate Maximum Quality Score (Fungible :)
πŸ‘©β€πŸŽ“ NEW GRAD

Imagine you're a seller on Amazon, specializing in eco-friendly products. Each of your items is rated by customers based on its quality and environmental impact.

The overall qualityScore of your products is determined by the maximum possible sum of consecutive ratings.

To improve the qualityScore of your products and attract more customers, you are given with an integer impactFactor and the following two strategies:

  • Amplify Ratings: Select a contiguous segment of ratings and amplify them by multiplying each rating in that range by impactFactor.
  • Adjust Ratings: Select a contiguous segment of ratings and adjust them by dividing each rating in that range by impactFactor
  • Your task is to determine the maximum possible qualityScore for your eco-friendly products after applying exactly one of these strategies.

    Note: When applying the second strategy i.e., Adjust Ratings; For dividing positive ratings, floor the division result, and for dividing negative ratings, use the ceiling value of the division result,

    Example: Given ratings = [4, -5, 5, -7, 1], and impactFactor = 2. If we choose to apply the second strategy with segment [2, 5] (Assuming 1-based indexing) then, modified ratings: [4, ceil(-5/2), floor(5/2 [I think it should be 5/2 instead of S / 2], ceil(-7/2), floor(1/2)] = [4, -2, 2, -3, 0]. Note that the ceil(-7/2) = -3 and floor(5/2) = 2,

    Given an array of ratings of size n and an integer impactFactor, determine the maximum possible qualityScore i.e., maximum possible sum of consecutive ratings by optimally selecting exactly one of the strategies to modify the ratings.

    Function Description

    Complete the function calculateMaxQualityScore in the editor below

    calculateMaxQualityScore has the following parameters:

    1. int impactFactor: the value used in the strategies to amplify or adjust ratings.
    2. int ratings[n]: an array representing the ratings of eco-friendly products

    Returns

    long: the maximum possible qualityScore of your eco-friendly products after applying exactly one of the strategies.

    Possible solution hint -> Basically, if the array is not entirely negative, find the max sum subarray and multiply it by the factor. If the array is entirely negative, find the single largest negative number and divide it by the factor.

    🐳 Hello spike! Thanks for carrying~ πŸ’ͺ

    Example 1:

    Input:  impactFactor = 2, ratings = [5, -3, -3, 2, 4]
    Output: 12
    Explanation:
    Let's try both the strategies with different contiguous ranges to get the maximum qualityScore: If we perform the first strategy on the subsegment [4, 5] (1-based indexing), we get the ratings = [5, -3, -3, 4, 8] with a qualityScore of 12, which is the maximum qualityScore. Hence, the answer is 12.

    Example 2:

    Input:  impactFactor = 1, ratings = [1]
    Output: 3
    Explanation:
    Since impactFactor = 1, applying any strategy will not change the ratings. The initial qualityScore is the maximum sum of consecutive ratings, which is 3. Note - The test cases and constraints are slightly different between the two sources I found. Example 1 and constraints are from source 1, while example 2 is from source 2.
    Constraints:
      • 1 <= n <= 2 * 10^5
      • 1 <= impactFactor <= 10^4
      • -10^5 <= ratings[i] <= 10^5
    Thumbnail 0
    Thumbnail 1
    Testcase

    Result
    Case 1

    input:

    output: