Maximum Alloy Production Within Budget
Updated
Problem statement
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) → longExamples
Example 1
composition = [1,2]stock = [0,1]cost = [1,1]budget = 3return = 1One 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 = 2The 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 = 3The 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