Round 1
Questions: Imagine you're a seller on Amazon, specializing in eco-friendly home 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, use the floor value of 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), 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.
Example
n = 5
ratings = [5, -3, -3, 2, 4]
impactFactor = 3
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.
Function Description:
Complete the function calculateMaxQualityScore in the editor below.
calculateMaxQualityScore has the following parameters:
- int impactFactor: the value used in the strategies to amplify or adjust ratings.
- 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.
Constraints
- 1 ≤ n ≤ 2105
- 1 ≤ impactFactor ≤ 104
- -105 ≤ ratings[i] ≤ 105
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.