The Shopping Offers interview question gives you prices for individual items, a list of bundle deals (each deal trades a set of items for a fixed price), and the desired quantities of each item. Find the minimum cost to buy exactly the required quantities, using any combination of bundle deals and individual item purchases. Items cannot be bought in excess of the requirement. This is a bitmask dynamic programming / memoized backtracking problem.
Amazon, Airbnb, and Google ask this problem because it models real-world e-commerce promotional pricing — a customer should find the optimal combination of discounts and individual purchases. It tests memoized backtracking with state represented as a tuple of remaining quantities. The pruning condition (no deal can buy more than needed) makes it a practical exercise in constraint-satisfying search.
The pattern is memoized DFS (backtracking + memoization). The state is the current needs tuple (remaining quantities for each item). For each state, either apply a valid bundle offer (if it doesn't exceed any item's need) or fall back to buying all remaining items individually. Cache dp[needs] = minimum cost for that need state. Transition: for each offer, if valid, recurse with needs - offer_quantities and add offer_price. Base case: needs = [0, 0, ..., 0] → cost = 0. The individual-purchase cost for any state is sum(needs[i] * price[i]).
prices = [2, 5], offers = [[3, 0, 5], [1, 2, 10]], needs = [3, 2].
Minimum: 14.
For the Shopping Offers coding problem, the dynamic programming bitmask memoization interview pattern is the clean approach. The key insight: represent remaining needs as an immutable tuple for memoization. Amazon and Airbnb interviewers appreciate that you validate offer applicability before recursing. Practice the "offer-or-individual" branching structure — it also appears in coin change variants where different denomination combinations lead to the same subproblem.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Partition to K Equal Sum Subsets | Medium | Solve | |
| Beautiful Arrangement | Medium | Solve | |
| Campus Bikes II | Medium | Solve | |
| Matchsticks to Square | Medium | Solve | |
| Minimum Number of Work Sessions to Finish the Tasks | Medium | Solve |