Find the Fewest Open Invoices That Exactly Match a Deposit

Last updated: November 29, 2026

Quick Overview

A customer sends one lump-sum payment without saying which invoices it covers. Given the deposit and the amounts of the open invoices in cents, return the smallest set of invoices whose amounts add up exactly to the deposit, or report that none exists.

Intuit
Coding & Algorithms
Software Engineer
Intuit
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


A customer sends one lump-sum payment without saying which invoices it covers. Given the deposit and the amounts of the open invoices in cents, return the smallest set of invoices whose amounts add up exactly to the deposit, or report that none exists.

Applying a single payment across multiple open invoices is a daily chore in QuickBooks, so Intuit interviewers use it as a dynamic programming problem with a concrete business story. They check that you see it as a 0/1 subset sum with a minimization objective, that you can reconstruct the chosen items, and that you discuss the pseudo-polynomial cost honestly.

What the Interviewer Expects
  • Identify the problem as 0/1 knapsack (subset sum) minimizing item count
  • Define the DP state and recurrence precisely
  • Reconstruct which invoices were chosen, not just the count
  • State the O(n x D) pseudo-polynomial complexity and when it becomes impractical
  • Propose practical fallbacks such as oldest-first application or meet in the middle
Key Topics to Cover
0/1 knapsack
subset sum
dynamic programming
reconstruction
pseudo-polynomial time
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
  • How would you reduce memory to O(D) while still recovering the chosen invoices?
  • If several minimal sets exist, how would you prefer the one with the oldest invoices?
  • The deposit is 2.1 million cents across 40 invoices. What would you do instead?
  • How would you handle a deposit that is short by a small processing fee?
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

Inputs: deposit and invoices, integers in cents. Each invoice can be used once. Return the indices of a minimum-size subset summing exactly to the deposit, or None. A deposit of 0 returns the em...

High-Level Design

Let best[i][s] be the fewest invoices among the first i that sum to exactly s. Either invoice i-1 is skipped (best[i-1][s]) or used (best[i-1][s - a] + 1). Base: best[0][0] = 0, everythi...


Submit Your Answer
Markdown supported

Related Questions