Alloy Production
Learn this problemProblem statement
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 nth metal in preparing 1 unit of the alloy is denoted by composition[n]. The company already has stock[n] units of metal in their stock.
The company has a budget to purchase any of the metals if needed. The cost of the nth metal is cost[n] 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.
Function
findMaximumAlloyUnits(composition: int[], stock: int[], cost: int[], budget: int) → int
Complete the function findMaximumAlloyUnits in the editor.
findMaximumAlloyUnits has the following parameters:
int composition[n]: the composition of metals in 1 unit of alloyint stock[n]: the units of metals type that the company has in stockint cost[n]: the cost of each metal typeint budget: the total money the company can spend
Returns
int: the maximum unit of alloys that can be produced
Examples
Example 1
composition = [1, 2]stock = [0, 1]cost = [1, 1]budget = 3return = 1A 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 3) = 4, 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 3) = 11, which is beyond the budget.
The answer is 1.
Constraints
1 ≤ n ≤ 10^51 ≤ budget ≤ 10^91 ≤ composition[i] ≤ 10^91 ≤ stock[i] ≤ 10^91 ≤ cost[i] ≤ 10^9composition[i] ≤ cost[i] ≤ 10^9More MathWorks problems
- Beautiful ArrangementONSITE INTERVIEW · Seen Jul 2026
- Find Minimum Cost to Remove Array ElementsONSITE INTERVIEW · Seen Jul 2026
- Group Shifted StringsONSITE INTERVIEW · Seen Jul 2026
- Longest Valid ParenthesesONSITE INTERVIEW · Seen Jul 2026
- Balancing TeamsOA · Seen Nov 2025
- Largest Sub-GridOA · Seen Nov 2025
- Discount TagsOA · Seen Oct 2024
- Odd One OutOA · Seen Oct 2024