UTXO Coin Selection That Avoids Dust Change Outputs
Last updated: November 29, 2026
Quick Overview
Given a Bitcoin wallet's unspent outputs, a target send amount and a fee rate in sats per vbyte, choose inputs that pay the amount plus fee, avoid creating a change output below the dust threshold, and skip inputs that cost more to spend than they are worth.
BitGo
November 29, 20260
0
0 solved
Given a Bitcoin wallet's unspent outputs, a target send amount and a fee rate in sats per vbyte, choose inputs that pay the amount plus fee, avoid creating a change output below the dust threshold, and skip inputs that cost more to spend than they are worth.
BitGo builds and signs UTXO transactions for BTC, LTC, BCH and others on behalf of high-volume wallets, where poor coin selection wastes fees and fragments the wallet. The onsite question checks whether a candidate can model fees that depend on the selection itself and reason about trade-offs.
What the Interviewer Expects
- Recognises the fee depends on the number of inputs and outputs, so it must be recomputed as inputs are added
- Filters out uneconomical UTXOs at the current fee rate
- Prefers a changeless match when one exists
- Folds sub-dust change into the fee instead of creating an unspendable output
- Discusses trade-offs of largest-first versus branch-and-bound or consolidation
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
- How would branch-and-bound find an exact changeless match?
- How does your choice affect privacy and future fees?
- How would you handle unconfirmed UTXOs?
- When should a wallet run a consolidation transaction?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: list of (id, value), amount, fee_rate. Assume P2WPKH-ish sizes: 11 vbytes overhead, 68 per input, 31 per output. Dust threshold 546 sats. Output: chosen inputs, the fee actually paid, an...
High-Level Design
Two passes. First look for a single UTXO that covers amount plus a one-output fee with less than a dust amount left over: that tx needs no change at all. Otherwise add UTXOs largest first, recomputing...