Maximum Product New Rating
Learn this problemProblem statement
The engineers at Amazon are working on a new rating system for their products. For each product, an array customer_rating is maintained for the last n orders of that product, where the rating given by the i-th customer is represented by customer_rating[i].
The following algorithm is used to calculate the new_rating of the product:
- The engineers can perform the following operation to the array
customer_ratingat mostktimes:- Choose a customer rating and add
1to that.
- Choose a customer rating and add
- The
new_ratingis the maximum Bitwise AND of anym-sized subset of the arraycustomer_rating.
Given n customer ratings, two integers m and k, and an array customer_rating, find the maximum possible new_rating of the product by performing the operations optimally.
Function
getMaximumNewRating(customer_rating: int[], m: int, k: int) → intExamples
Example 1
customer_rating = [1, 2, 4, 8]m = 2k = 8return = 10Given n = 4, k = 8, m = 2, and customer_rating = [1, 2, 4, 8].
One of the optimal ways is explained below:
customer_rating[3] 6 timescustomer_rating[4] 2 times- Apply the operation on
customer_rating[3]6times to getcustomer_rating = [1, 2, 10, 8]. - Apply the operation on
customer_rating[4]2times to getcustomer_rating = [1, 2, 10, 10].
The optimal subset of size 2 is [10, 10] with a Bitwise AND of 10.
Note that there could also be other possible modifications of the array customer_rating, for example: customer_rating = [1, 2, 4, 16] (all the operation performed on the last element). However, the optimal m-sized subset in this case can be any two elements all with same Bitwise AND of 0.
It is guaranteed that there is no other possible modification of the array customer_rating that results in yielding the Bitwise AND of an m-sized subset greater than 10.
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026