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.
customer_rating = [1, 2, 4, 8] m = 2 k = 8 return = 10
Given 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.
- Permutation SorterOA · Seen Jul 2026
- Get Distinct Pairs (Also apply to AS intern)Seen Jul 2026
- Maximum Final ValueSeen Jul 2026
- Minimum Delivery Center InconvenienceOA · Seen Jun 2026
- Unfulfilled Customers by Inventory PriorityOA · Seen Jun 2026
- Minimum Operations to Make the Integer ZeroSeen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA · Seen Jun 2026
public int getMaximumNewRating(int[] customer_rating, int m, int k) {
// write your code here
}