FastPrepFastPrep
Problem Brief

Get Minimum Cost

FULLTIMEOA

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 Description

    Complete the function getMinimumCost in the editor.

    getMinimumCost has the following parameters:

    1. 1. int vouchersCount: the number of discount vouchers
    2. 2. int[] prices: an array of integers representing the prices of the items

    Returns

    intint: the minimum cost after applying the vouchers

    1Example 1

    Input
    vouchersCount = 3, prices = [8, 2, 13]
    Output
    9
    Explanation
  • 13 / 2^2 = 3
  • 8 / 2^1 = 4
  • 2 / 2^0 = 2
  • Total = 3 + 4 + 2 = 9.

    Constraints

    Limits and guarantees your solution can rely on.

    🥭🥭
    public int getMinimumCost(int vouchersCount, int[] prices) {
      // write your code here
    }
    
    Input

    vouchersCount

    3

    prices

    [8, 2, 13]

    Output

    9

    Sign in to submit your solution.