🎁 Exclusive Offer! Join our
Telegram Channel
to get **special discounts** and updates! 🚀
Question 49 - 100% Working Solution | Buy Now
Description
8 Live
Modified Knapsack Problem
The Knapsack problem is a well-known problem in the field of computer programming and problem-solving. To make it more interesting, an interviewer uses a modified version of the problem.
Given n items, where the weight of the i-th item is 2^i, and the cost of the i-th item is cost[i], find the minimum amount needed to purchase the items such that the combined weight of the purchased items is at least minWeight.
Example
Consider n = 5 ,cost = [2, 5, 7, 11, 25] ,minWeight = 26
One of the optimal ways to purchase the items is as follows:
Buy 2 units of the 0th item and 3 units of the 3rd item.
Total cost = (2 × 2) + (3 × 11) = 37.
Total weight = (2 × 2^0) + (3 × 2^3) = 26, which is at least minWeight.
Return the total cost of the items, 37.
Function Description
Complete the function getMinimumCost in the editor below.
getMinimumCost has the following parameters:
- int cost[n]: the cost of each item
- int minWeight: the minimum combined weight