MICROSOFT Coding Question – Solved

6 Live
A foundry in Hackerland makes an alloy out of n different metals. In the manufacturing of an alloy, the composition of each metal is fixed, where the required quantity of the i-th metal in preparing 1 unit of the alloy is denoted by composition[i]. The company already has stock[i] units of metal i in their stock. The company has a budget to purchase any of the metals if needed. The cost of the i-th metal is cost[i] per unit. Find the maximum units of alloys the company can produce by using available stock plus what they can purchase within their budget. Note: Their supplier has an infinite supply of all metal types. Example: There are n = 2 metal types. - their required composition = [1, 2] - their available stock = [0, 1] - their purchase cost = [1, 1] - their budget = 3 A maximum of 1 unit of alloy can be produced. - The cost for 1 unit: required quantity = [1, 2], stock = [0, 1], extra metal requirements = [1, 1], cost = (1 x 1) + (1 x 1) = 2, which is within the budget. - The cost for 2 units: required quantity = [2, 4], stock = [0, 1], extra metal requirements = [2, 3], cost = (2 x 1) + (3 x 1) = 5, which is beyond the budget. The answer is 1. Function Description: Complete the function findMaximumAlloyUnits in the editor below. findMaximumAlloyUnits has the following parameters: int composition[n]: the composition of metals in 1 unit of alloy int stock[n]: the units of metals type i that the company has in stock int cost[n]: the costs of metals type i. int budget: the total money the company can spend Returns: int: the maximum unit of alloys that can be produced Constraints: 1 ≀ n ≀ 10^5 1 ≀ budget ≀ 10^9 1 ≀ composition[i] ≀ 10^5 1 ≀ stock[i] ≀ 10^5 1 ≀ cost[i] ≀ 10^5 composition[i] * cost[i] ≀ 2 * 10^9 Input Format For Custom Testing: The first line contains an integer, n, the number of elements in array composition. Each line i of the next n subsequent lines (where 0 ≀ i < n) contains an integer, composition[i]. The next line contains an integer, n, the number of elements in array stock. Each line i of the next n subsequent lines (where 0 ≀ i < n) contains an integer, stock[i]. The next line contains an integer, n, the number of elements in array cost. Each line i of the next n subsequent lines (where 0 ≀ i < n) contains an integer, cost[i]. The next line contains an integer, budget.

Asked in: MICROSOFT

Image of the Question

Question Image Question Image Question Image Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| As an operations engineer at Amazon, you are responsible for organizing the dis… |
| Amazon Books is a retail store that sells the newly launched novel "The Story o… |
| In an Amazon analytics team, the Analysts collectively have a preference for th… |
| AWS provides scalable systems. A set of n servers are used for horizontally sca… |
| An array of integers is almost sorted if at most one element can be deleted fro… |
| The binary cardinality of a number is the count of 1's in its binary representa… |