Select UTXOs That Cover a Payment Plus Per-Input Fees
Last updated: November 29, 2026
Quick Overview
Given a wallet's unspent output values, a payment target and a fee charged per input used, choose a subset whose total minus fees covers the target while consuming the smallest possible total amount.
Coinbase
November 29, 20260
0
0 solved
Given a wallet's unspent output values, a payment target and a fee charged per input used, choose a subset whose total minus fees covers the target while consuming the smallest possible total amount.
Coinbase sends Bitcoin from wallets holding many UTXOs, and coin selection drives both network fees and how much change gets created. The interviewer looks for a 0/1 knapsack style DP, why greedy fails, and a correct reconstruction of the chosen inputs.
What the Interviewer Expects
- Show why largest-first or smallest-first greedy can be suboptimal
- Define dp over exact sums with the fewest inputs needed
- Explain why fewest inputs is the right state for a given sum when fees grow with inputs
- Iterate sums in descending order so each UTXO is used once
- Reconstruct chosen indices without mixing stages
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Real fees depend on transaction size in vbytes; how does the model change?
- Values can be up to 10^8 satoshis; how would you make this tractable?
- How would you prefer solutions with no change output at all?
- How do privacy concerns affect which UTXOs you combine?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Integer UTXO values, a target and a per-input fee. A subset with total s and c inputs is valid when s - fee * c >= target. Among valid subsets minimize s, which minimizes change. Return `(s, i...
High-Level Design
For a fixed total s, using fewer inputs only helps feasibility, so the state best[s] = fewest inputs summing exactly to s is sufficient. This is 0/1 knapsack: process each UTXO and update sums fro...