Cheapest Way to Fill a Shopping List Using Bundle Offers

Last updated: November 29, 2026

Quick Overview

A Google Shopping cart lists the quantity needed of each item, the single-unit price of each item, and several bundle offers that give fixed quantities of items for a fixed price. Find the minimum cost to buy exactly the needed quantities, never exceeding any need.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


A Google Shopping cart lists the quantity needed of each item, the single-unit price of each item, and several bundle offers that give fixed quantities of items for a fixed price. Find the minimum cost to buy exactly the needed quantities, never exceeding any need.

A Google onsite problem that combines backtracking over offers with memoization on the remaining needs. The interviewer checks that you treat buying the rest at unit price as the baseline, reject offers that overshoot, and memoize the needs tuple.

What the Interviewer Expects
  • Uses the unit-price total of the remaining needs as the baseline
  • Tries each offer that fits without exceeding any need
  • Memoizes on the tuple of remaining needs
  • Filters out offers that cost more than buying their items individually
  • Explains state space size as the product of (need + 1)
Key Topics to Cover
Backtracking
Memoization
Dynamic programming
Combinatorial optimization
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 you are allowed to buy more than needed?
  • How would you limit how many times each offer can be used?
  • How would you return which offers to buy?
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: price[i] for n items (n <= 6), needs[i] (each <= 10), and offers, each a list of n quantities followed by the bundle price.
  • Output: the minimum cost. Offers may be used any number of ...
High-Level Design

Define best(needs) = min cost to buy exactly these remaining needs.

  1. Baseline: buy everything at unit price, sum(price[i] * needs[i]).
  2. For each offer whose every quantity is at most the corr...

Submit Your Answer
Markdown supported