As reported: BNY on-campus internship test on HackerRank (1.5 hours, two DSA questions and one development question). Q1, "Find Minimum Price to Pay": an array of item prices and
mcoupons; usingkcoupons on itemibrings its price down based onprice[i] / 2^k; distribute the coupons so the total price paid is minimum. Tagged priority queue.
You are given an integer array prices and an integer m. Using k coupons on item i makes its price floor(prices[i] / 2^k) — each coupon on an item halves its current price, rounding down. Any number of coupons may go to the same item, and at most m coupons are used in total.
Return the minimum total price of all items.
Example 1
prices = [10, 4, 3], m = 3 -> 7
Halve 10 → 5 ([5,4,3]), halve 5 → 2 ([2,4,3]), halve 4 → 2 ([2,2,3]). Total 7.
Example 2
prices = [8], m = 4 -> 0
8 → 4 → 2 → 1 → 0.
Example 3
prices = [5, 5], m = 0 -> 10
Constraints: 1 ≤ n ≤ 10^5; 1 ≤ prices[i] ≤ 10^9; 0 ≤ m ≤ 10^5. The total can exceed 32 bits.
Code runner format: one JSON value per line: prices, then m. Implement minimumPrice(prices, m); the harness prints the total.