Fewest Azure VMs to Exactly Fill a Core Quota
Last updated: November 29, 2026
Quick Overview
Given the vCPU core counts of the available Azure VM sizes (unlimited supply of each) and a target core quota, return the fewest VMs whose cores sum exactly to the quota, plus one such selection, or -1 if impossible.
Microsoft
November 29, 20260
0
0 solved
Given the vCPU core counts of the available Azure VM sizes (unlimited supply of each) and a target core quota, return the fewest VMs whose cores sum exactly to the quota, plus one such selection, or -1 if impossible.
An unbounded knapsack question framed around Azure capacity planning. The interviewer checks that the candidate rejects a greedy largest-first approach with a counterexample and builds a bottom-up DP with reconstruction.
What the Interviewer Expects
- Show why greedy (largest size first) fails, e.g. sizes [1,3,4] and quota 6
- Define best[q] as fewest VMs summing to q
- Return -1 when unreachable
- Reconstruct one optimal selection with a choice array
- State O(quota x sizes) complexity
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Count the number of distinct combinations instead of the minimum count.
- What if each size has a limited stock?
- The quota is 10^9 but sizes are small. What would you do?
- Minimize cost when each size has a price, still hitting the exact quota.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
sizes: positive integers (cores per VM size).quota: non-negative integer.- Each size can be used any number of times.
- Return
(count, picks)or(-1, [])....
High-Level Design
Greedy fails: with sizes [1,3,4] and quota 6, largest-first gives 4+1+1 (3 VMs) while 3+3 needs 2. So use DP: best[0] = 0, and best[q] = 1 + min(best[q - s]) over sizes s <= q. Store which size ...