Flipkart Coding Question – Solved

10 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

Asked in: Flipkart

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| The supply chain manager at one of Amazon's warehouses is shipping the last con… |
| Determine the highest value after executing n steps on an infinite 2D grid that… |
| Amazon Prime Video is developing a new feature called "Segmentify." This featur… |
| In this new stock prediction game launched on Amazon Games, Player 1 provides P… |
| Amazon operates numerous warehouses, with each warehouse holding inventory[i] u… |
| In Amazon's highly efficient logistics network, minimizing operational overhead… |