Get Minimum Cost
Alex is a TikTok influencer who loves shopping online and sharing his latest hauls with his followers. He's super excited about buying several products from an e-commerce website to feature in his next video. Each item on his shopping list has its own price, and Alex wants to show his followers how to get the best deals.
Alex has a number of discount vouchers that he can use on any of his purchases. These vouchers offer a unique discount mechanism: the more vouchers used on a single item, the greater the discount. For instance, for each voucher used on an item, the price of that item is halved. If multiple vouchers are used on the same item, the price is halved repeatedly.
The discount can be represented by the following formula:
discounted price = p / 2^k
where:
p is the original price of the item.k is the number of vouchers used on that item.
Complete the function getMinimumCost in the editor.
getMinimumCost has the following parameters:
- 1.
int vouchersCount: the number of discount vouchers - 2.
int[] prices: an array of integers representing the prices of the items
Returns
intint: the minimum cost after applying the vouchers
1Example 1
Constraints
Limits and guarantees your solution can rely on.
ðŸ¥ðŸ¥