← Coinbase Interview Insights

Coinbase·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026Remote

Summary

Coinbase SWE interview that was pretty much a knapsack problem dressed up in blockchain clothes. The follow-up on dependency trees was the part that actually made me sweat.

Questions Asked (2)

Q1

Given a list of transactions each with an id, size, and fee, and a block size limit of 100, how would you select a subset of transactions that maximizes total fee without exceeding the size limit?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was DP since it's basically a knapsack variant, but the interviewer steered me toward a greedy approach instead, sorting by fee-to-size ratio.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize this as a 0/1 knapsack problem where transaction size is weight and fee is value, with block size as capacity. Present a dynamic programming solution that maximizes total fee, then discuss time/space complexity and potential optimizations for large transaction pools.

Pro tip: Mention that in real blockchain systems, transaction selection often uses a greedy approach based on fee rate (fee per byte) for simplicity and speed, but DP guarantees optimality for small block sizes like 100. This shows awareness of practical trade-offs.

1. Clarify the problem

Confirm that each transaction can be included at most once (0/1 knapsack), and that the goal is to maximize total fee without exceeding the block size limit.

2. Define DP state and recurrence

Let dp[i][s] be the maximum fee using the first i transactions with total size exactly s (or at most s). Recurrence: dp[i][s] = max(dp[i-1][s], dp[i-1][s - size_i] + fee_i) if size_i <= s.

3. Implement and optimize space

Use a 1D DP array of size block_limit+1, iterating transactions and updating from high to low size to avoid reusing items. Time O(n * block_size), space O(block_size).

4. Reconstruct selected transactions

If needed, backtrack through the DP table to identify which transactions were chosen, or maintain a parent pointer during computation.

5. Discuss trade-offs and alternatives

Compare DP with greedy by fee rate, noting that greedy is faster but not always optimal; for block size 100, DP is efficient. Also mention potential integer overflow and use of 64-bit integers for fees.

Key Points to Mention

  • 0/1 knapsack problem mapping: size as weight, fee as value, block limit as capacity
  • Dynamic programming recurrence and 1D space optimization
  • Time complexity O(n * block_size) and space O(block_size)
  • Greedy alternative by fee rate (fee/size) and its limitations
  • Reconstruction of selected transactions if required
  • Practical considerations: integer overflow, large n, and real-world blockchain constraints

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

Q2

Follow-up: if transactions have parent-child dependencies where a child transaction can only be included in the block if its parent is also included, how would you modify your selection approach?

Algorithms & Data StructuresSystem Design
Author's notes

This is where I fumbled a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Acknowledge that the parent-child dependency introduces a precedence constraint, so the selection problem becomes a constrained optimization. Propose modeling transactions as a DAG and using a modified greedy algorithm that respects dependencies, such as selecting transactions in topological order or using a priority queue that only considers transactions whose parents are already selected.

Pro tip: Mention that in practice, you might need to handle cycles or missing parents gracefully, and consider the trade-off between optimality and computational complexity—sometimes a simple heuristic like 'include all ancestors' is sufficient for real-world blockchains.

1. Model dependencies as a DAG

Represent transactions as nodes and parent-child relationships as directed edges. This clarifies that a child can only be selected if all its ancestors are selected.

2. Adapt selection algorithm

Modify your existing selection approach (e.g., greedy by fee) to only consider transactions whose parents are already included. Use a priority queue of 'available' transactions (those with no unselected parents).

3. Handle ordering and feasibility

Ensure that when you select a transaction, you also add its children to the available set. If a parent is not selected, its children remain unavailable.

4. Consider optimization goals

Discuss whether to maximize total fee, minimize block size, or other objectives. Note that the dependency constraint may reduce the achievable optimal value compared to unconstrained selection.

5. Address edge cases and scalability

Mention handling of cycles (invalid), missing parents (ignore or treat as invalid), and performance implications for large DAGs. Suggest possible optimizations like precomputing ancestor sets.

Key Points to Mention

  • Topological sorting or Kahn's algorithm to process transactions in dependency order
  • Priority queue (max-heap) keyed by fee rate, but only for transactions with all parents selected
  • The problem is a variant of the knapsack problem with precedence constraints, which is NP-hard in general
  • Greedy approach may not be optimal, but is often used in practice for its simplicity and speed
  • Need to handle transactions with multiple parents (e.g., DAG) and ensure all are included
  • Consider using dynamic programming for small dependency graphs or if optimality is critical

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