← Coinbase Interview Insights

Coinbase·Software Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Jun 2026Remote

Summary

Coinbase SWE interview with a two-part coding problem around block mining and transaction selection. The dependency constraint part was the real test and I felt underprepared for the graph angle it took.

Questions Asked (2)

Q1

You're building a block from a transaction pool. Given a block size limit, how do you select a subset of independent transactions that maximizes total fees?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Pretty standard knapsack framing once you see it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: it's a 0/1 knapsack where items are transactions with weights (size) and values (fees), but with the added constraint that transactions may have dependencies (e.g., child spends parent's output). For independent transactions, the optimal solution is to sort by fee rate (fee per byte) and greedily include until the block is full. If dependencies exist, model as a DAG and use a greedy approach on effective fee rates or dynamic programming for small blocks.

Pro tip: Mention that in practice, miners often use a greedy algorithm based on fee rate because it's fast and near-optimal, but you should also discuss the trade-off between optimality and computational complexity, especially for large mempools.

1. Clarify the problem

Confirm that transactions are independent (no dependencies) and that the goal is to maximize total fees within a block size limit. Ask if fractional inclusion is allowed (it's not).

2. Identify the algorithmic problem

Recognize this as the 0/1 knapsack problem, which is NP-hard in general. However, for independent transactions, a greedy approach by fee rate is optimal if we can take fractions, but not for 0/1. Discuss that the greedy by fee rate is a common heuristic.

3. Propose a solution

For independent transactions, sort by fee rate descending and include transactions until the block is full. This is not always optimal for 0/1 knapsack, but it's efficient and widely used. For exact optimality, use dynamic programming if the block size is small.

4. Discuss trade-offs

Compare greedy vs. dynamic programming: greedy is O(n log n) and near-optimal, DP is O(n * block_size) and optimal but may be too slow for large blocks. Mention that in practice, miners use greedy with fee rate.

5. Address dependencies

If transactions have dependencies (e.g., a child transaction spends an output from a parent), model as a DAG and use a modified greedy approach or dynamic programming on the DAG. Mention that this is more complex and often handled by package selection.

Key Points to Mention

  • 0/1 knapsack problem and its NP-hardness
  • Greedy algorithm by fee rate (fee per byte) as a practical heuristic
  • Dynamic programming for exact optimality when block size is small
  • Trade-off between optimality and computational efficiency
  • Transaction dependencies and how they complicate the problem
  • Real-world implementation in Bitcoin and other cryptocurrencies

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Now each transaction can declare parent transactions as dependencies. A transaction can only be included in a block if all its ancestors are also included. How do you redesign the selection algorithm to respect these dependency constraints while still maximizing fees?

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

This is where I fumbled a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model transactions and dependencies as a directed acyclic graph (DAG) and reframe the problem as selecting a maximum-weight closure (or knapsack on a DAG) to maximize fees while respecting ancestor inclusion. Discuss both exact approaches (e.g., min-cut) and practical heuristics (e.g., greedy with topological ordering and priority queues) that balance optimality and performance.

Pro tip: Acknowledge that the exact maximum-weight closure can be solved via min-cut, but in a real system you'd likely use a greedy heuristic with a priority queue and topological constraints to meet latency and throughput requirements.

1. Model the problem

Represent transactions as nodes in a DAG with edges from parent to child, and assign each node a weight equal to its fee. The goal is to select a subset of nodes that is closed under ancestors (if a node is selected, all its ancestors must be selected) while maximizing total weight.

2. Identify the algorithmic problem

Recognize this as the maximum-weight closure problem, which can be solved exactly in polynomial time using a reduction to min-cut/max-flow. Alternatively, it can be seen as a precedence-constrained knapsack, which is NP-hard in general, so exact solutions may not scale.

3. Design an exact solution (if needed)

Construct a flow network: source connects to positive-weight nodes with capacity equal to weight, negative-weight nodes connect to sink with capacity equal to absolute weight, and infinite-capacity edges represent dependencies. The min-cut gives the optimal set of transactions to include.

4. Propose a practical heuristic

For real-time block building, use a greedy approach: compute a topological order, maintain a priority queue of available transactions (those whose ancestors are all included), and iteratively pick the highest-fee transaction that fits within the block size limit. This respects dependencies and is efficient.

5. Discuss trade-offs and optimizations

Compare exact vs. heuristic approaches in terms of optimality, time complexity, and scalability. Mention potential optimizations like caching, incremental updates, or using approximation algorithms for large DAGs.

Key Points to Mention

  • Directed acyclic graph (DAG) representation of transactions and dependencies
  • Maximum-weight closure problem and its reduction to min-cut/max-flow
  • Precedence-constrained knapsack and NP-hardness implications
  • Greedy heuristic with topological ordering and priority queue
  • Block size limit as a knapsack constraint
  • Trade-offs between optimality, latency, and throughput in production systems

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.