Find Every Ad Package Combination That Spends the Exact Budget

Last updated: November 29, 2026

Quick Overview

Given distinct positive ad package prices and a budget, return every combination of packages whose prices sum exactly to the budget. A package may be bought any number of times, and combinations are unordered.

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

0

0

0 solved


Given distinct positive ad package prices and a budget, return every combination of packages whose prices sum exactly to the budget. A package may be bought any number of times, and combinations are unordered.

Small businesses on Meta often want to spend a fixed budget exactly across boost packages, which frames this classic combination-sum style search. The interviewer checks that you avoid ordered duplicates, prune with sorting, and allow reuse correctly.

What the Interviewer Expects
  • Sort prices to enable early break pruning
  • Pass the current index to allow reuse while avoiding reorderings
  • Stop the branch when remaining budget hits zero
  • Explain why passing i + 1 would forbid reuse
  • Discuss exponential worst case and when DP counting is better
Key Topics to Cover
Backtracking
Pruning
Combinations
Dynamic programming
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
  • What if each package can be bought at most once and prices may repeat?
  • How would you only count combinations, for a budget of 10^5?
  • How would you return the combination that uses the fewest packages?
  • How would you cap the number of packages at k?
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
  • Prices are positive and distinct (dedupe defensively).
  • Budget up to a few hundred.
  • Return each multiset once, in any order....
High-Level Design

Sort prices. Recurse with (start, remaining): try each price from start onward; if it exceeds remaining, break because all later prices are larger. Otherwise take it and recurse with the same in...


Submit Your Answer
Markdown supported