Alloy Production
Updated
Problem 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^9
More MathWorks interview questions
- Earliest Time to Schedule a MeetingOA · Seen Nov 2026
- Minimum Cost to Serve Requests on a RingOA · Seen Nov 2026
- Minimum Tree Diameter After Removing K LeavesOA · Seen Nov 2026
- Cities on Shortest Delivery RoutesOA · Seen Nov 2026
- Repeated Mirror XOROA · Seen Nov 2026
- 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
Similar questions at other companies
- Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
- Find Minimum TimeAlphaSense · OA
- Find Minimum TimeBlackRock · OABlackRock interview questions
- Maximize Pipeline Throughput Under a Scaling BudgetMicrosoft · OAMicrosoft interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Minimum Robot and Human Fulfillment TimeAmazon · OA
- Minimize Maximum Group DifferenceDRW · OADRW interview questions
- Array NullificationQRT · OA
- Minimum HeightSnowflake · OASnowflake interview questions
- Pipeline Throughput Maximization Under BudgetUber · OAUber interview questions