FastPrepAlloy Production
Problems/Alloy Production

Alloy Production

MathWorks logoMathWorks● MediumOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

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:

  1. int composition[n]: the composition of metals in 1 unit of alloy
  2. int stock[n]: the units of metals type that the company has in stock
  3. int cost[n]: the cost of each metal type
  4. int 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 = 1

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 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^5
  • 1 ≤ budget ≤ 10^9
  • 1 ≤ composition[i] ≤ 10^9
  • 1 ≤ stock[i] ≤ 10^9
  • 1 ≤ cost[i] ≤ 10^9
  • composition[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

MathWorks interview experiences

  • MathWorks SWE Intern Phone Screens: 1 Experience
  • MathWorks Software Engineer in Test OA and HireVue: 1 Experience
All MathWorks interview questionsSee MathWorks hiring insights
Saved
class Solution {
    public int findMaximumAlloyUnits(int[] composition, int[] stock, int[] cost, int budget) {
      // write your code here
    }

}
Checking account…