Count Combinations of Storage Add-Ons That Sum to a Quota
Last updated: November 29, 2026
Quick Overview
Google One sells storage add-ons in fixed sizes that can be bought any number of times. Count the distinct multisets of add-ons whose sizes sum to exactly Q gigabytes; order of purchase does not matter.
0
0
0 solved
Google One sells storage add-ons in fixed sizes that can be bought any number of times. Count the distinct multisets of add-ons whose sizes sum to exactly Q gigabytes; order of purchase does not matter.
This tests whether you understand why loop order changes what a counting DP counts, a point Google interviewers probe directly. Many candidates accidentally count permutations; the strong answer explains the loop order before writing it.
What the Interviewer Expects
- Distinguish combinations from permutations explicitly
- Iterate items in the outer loop and amounts in the inner loop
- Explain why that order counts each multiset once
- Use a single 1D array updated in place
- Handle Q = 0 and impossible quotas
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 ordered purchase sequences instead.
- Each add-on may be bought at most once.
- Return the count modulo a prime for large Q.
- Count combinations using at most m add-ons in total.
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 sizes of distinct positive integers and integer Q >= 0. Output the number of multisets of sizes summing to Q. With sizes [1, 2, 5] and Q = 5 there are 4: 5, 2+2+1, 2+1+1+1, 1+1+1+1+1....
High-Level Design
Let ways[q] be the number of multisets summing to q using the add-ons processed so far. Process add-on sizes one at a time. When adding size s, any multiset that now uses s at least once is a multis...