FastPrepFind Minimum Price to Spend

Find Minimum Price to Spend

PayPal logoPayPal● MediumOA
Learn

Problem 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. 1. int[] price: an array of integers representing the price of each item
  2. 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

  • 🦦

More PayPal problems

See PayPal hiring insights
public int findMinimumPriceToSpend(int[] price, int m) {
  // write your code here
}
price[1, 2, 3]
m2
expected3
Checking account…