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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

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
1D dynamic programming
Coin change ways
Loop order
Combinations vs permutations
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported