Get Minimum Cost
Learn this problemProblem statement
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.Function
getMinimumCost(vouchersCount: int, prices: int[]) → int
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
Examples
Example 1
vouchersCount = 3prices = [8, 2, 13]return = 9Constraints
🥭🥭More Tiktok problems
- Can Reach the Exit with TeleportsOA · Seen Jul 2026
- Check Monotonic TriplesOA · Seen Jul 2026
- Shift Every K-th ConsonantOA · Seen Jul 2026
- Count Access Code PairsOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026
- Sort Matrix BordersOA · Seen Jul 2026
- Travel Distance on ScootersOA · Seen Jul 2026
- Validate 3x3 Digit WindowsOA · Seen Jul 2026