Choose Spare Disks Used at Most Once to Hit an Exact Capacity
Last updated: November 29, 2026
Quick Overview
A data center tech has a bin of spare disks with sizes that may repeat, and each physical disk can be used once. Return every distinct set of disk sizes whose total equals the requested capacity.
0
0
0 solved
A data center tech has a bin of spare disks with sizes that may repeat, and each physical disk can be used once. Return every distinct set of disk sizes whose total equals the requested capacity.
Asked in Google onsite coding rounds as the follow-up to unlimited-reuse combination sum. The interviewer checks that you combine single-use recursion (start at i + 1) with sibling-level duplicate skipping on sorted input.
What the Interviewer Expects
- Advances to i + 1 so each disk is used at most once
- Skips equal sizes at the same depth to avoid duplicate sets
- Sorts and breaks early once a size exceeds the remaining capacity
- Explains why a set of tuples is a worse fix
- Traces an example with repeated sizes
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
- How would you return just one valid set as fast as possible?
- How would you minimize the number of disks used?
- If sizes are large but few distinct values exist, how would you search by value counts instead?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list of positive disk sizes in TB, possibly repeated, for example
[10, 1, 2, 7, 6, 1, 5], and target8. - Output: distinct multisets of sizes summing to 8, each sorted:
[1,1,6], `[1,2,5...
High-Level Design
Sort the sizes. Recurse with (start, remaining). At each node, loop i from start:
- If
i > startandsizes[i] == sizes[i-1], skip, because picking this equal disk as the next item duplicat...