Problem Brief
Items Purchase (For Java Backend Engineer)
OA
n items where the price of the ith item is price[i]. A frequent customer has m discount coupons. If x discount coupons are used on the ith item, its price is reduced to the integer floor(price(i) / 2^x), e.g. floor(3/2^1) = floor(1.5) = 1.
Find the minimum amount needed to purchase all the items of the shop using at most m coupons.
Function Description
Complete the function findMinimumPrice in the editor below.
findMinimumPrice has the following parameters:
int price[n]: the original prices of the itemsint m: the number of discount coupons
Returns
int: the minimum amount needed to purchase all items
1Example 1
Input
price = [2, 4], m = 2
Output
3
Explanation
The optimum solution:
- Purchase item 1 for 2.
- Use 2 coupons on item 2, so the discounted price is 4/2^2 = 4 / 4 = 1.
Constraints
Limits and guarantees your solution can rely on.
1 <= n <= 10^50 <= m <= 10^91 <= price[i] <= 10^9