FastPrepMaximum Alloy Production Within Budget
Problems/Maximum Alloy Production Within Budget

Maximum Alloy Production Within Budget

Microsoft logoMicrosoft● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Microsoft intern online assessment. The report defines one alloy recipe, the stock on hand, the cost of buying each metal, a budget, the goal of making the most, and a worked example. It also recommends binary search. It leaves out the function signature and the limits on the numbers. Our version is about 97% the same as the reported question.

A foundry produces one alloy using n different metals. For each metal i:

  • composition[i] is the quantity required to produce one unit of alloy.
  • stock[i] is the quantity already available.
  • cost[i] is the purchase price per additional unit.

You may buy any nonnegative integer quantity of each metal, spending at most budget in total. Return the maximum whole number of alloy units that can be produced using the initial stock plus the purchased metals.

Function

maxAlloyUnits(composition: int[], stock: int[], cost: int[], budget: long) → long

Examples

Example 1

composition = [1,2]stock = [0,1]cost = [1,1]budget = 3return = 1

One unit needs purchases [1,1] costing 2. Two units need purchases [2,3] costing 5, which exceeds the budget.

Example 2

composition = [2,1]stock = [4,0]cost = [3,2]budget = 4return = 2

The existing first metal covers two alloy units, and buying two units of the second metal costs exactly 4.

Example 3

composition = [3]stock = [10]cost = [5]budget = 0return = 3

The stock alone produces three complete units, with one unit of metal left over.

Constraints

  • 1 <= composition.length == stock.length == cost.length <= 100000.
  • 1 <= composition[i] <= 10^9.
  • 0 <= stock[i] <= 10^9.
  • 1 <= cost[i] <= 10^9.
  • 0 <= budget <= 10^18.
  • The answer fits in a signed 64-bit integer.

More Microsoft Online Assessment questions

  • Authentication SystemOA · Seen Nov 2026
  • Maximum String OperationsOA · Seen Nov 2026
  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
  • Maximum Interactive Team SizeOA · Seen Nov 2026
  • Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
  • Minimum Cost K-Capable ModelsOA · Seen Nov 2026
  • Find Available Meeting RoomsOA · Seen Oct 2026

Similar questions at other companies

  • Linear InterpolatorTwo Sigma · OATwo Sigma interview questions
  • Rock JumpingIMC Trading · OAIMC Trading interview questions
  • Souvenir Shop PurchasesAmazon · OA
  • TikTok Video Relevance AdjustmentTikTok · OATikTok interview questions
  • Minimum Bonus ProjectsWells Fargo · OAWells Fargo interview questions
  • Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Koko Eating BananasTekion · ONSITE INTERVIEWTekion interview questions
  • Minimum of a Convex FunctionRippling · PHONE SCREENRippling interview questions
  • Count Centaur Friend RequestsMeta · PHONE SCREENMeta interview questions
  • Percentile and Boundary QueriesDatadog · PHONE SCREENDatadog interview questions

Interview reports that mention this question

  • Microsoft OA Questions, October 2026: 4 Experiences

Microsoft interview experiences

  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public long maxAlloyUnits(int[] composition, int[] stock, int[] cost, long budget) {
        // Write your code here.
    }
}
Checking account…