Problem · Heap
Find Minimum Price to Spend
Learn this problemProblem statement
Given an array price[1-n] and m (discount), find the minimum price to spend to buy all the items.
Use the following formula to apply the coupon: price[i] / 2^x, where x is the number of coupons used, and i is the index of the item in the array.
Function
findMinimumPriceToSpend(price: int[], m: int) → int
Complete the function findMinimumPriceToSpend in the editor.
findMinimumPriceToSpend has the following parameters:
- 1.
int[] price: an array of integers representing the price of each item - 2.
int m: the number of discounts available
Returns
int: the minimum price to spend
Examples
Example 1
price = [1, 2, 3]m = 2return = 3🦦
Constraints
🦦