Order Pending Transactions by Nonce and Explicit Dependencies
Last updated: November 29, 2026
Quick Overview
Given pending transactions, each with a sender, a nonce and a fee, plus explicit before/after dependencies, produce a broadcast order that keeps every sender's nonces consecutive and respects dependencies, preferring higher fees whenever several are ready. Return an empty list if no valid order exists.
Coinbase
November 29, 20260
0
0 solved
Given pending transactions, each with a sender, a nonce and a fee, plus explicit before/after dependencies, produce a broadcast order that keeps every sender's nonces consecutive and respects dependencies, preferring higher fees whenever several are ready. Return an empty list if no valid order exists.
Coinbase's wallet and blockchain infrastructure teams broadcast large batches of on-chain transactions where account nonces must be used in order. The interviewer is checking that you recognize a topological sort, combine implicit nonce edges with explicit ones and detect both gaps and cycles.
What the Interviewer Expects
- Derive implicit edges from consecutive nonces per sender
- Detect nonce gaps or duplicates up front
- Run Kahn's algorithm with a max-heap on fee for tie-breaking
- Detect cycles by checking the output length
- Explain complexity including the heap
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 you handle a stuck low-fee transaction blocking a sender's later ones?
- How do you adapt this when new transactions arrive continuously?
- What if the block has a gas limit and you must choose a subset?
- How would you make the tie-breaking deterministic across replicas?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: txs mapping id to (sender, nonce, fee) and deps as (before, after) pairs. For each sender, transactions must appear in nonce order with no gaps. Among ready transactions pick the highes...
High-Level Design
Build one graph. For each sender, sort by nonce and add an edge between consecutive transactions; a jump of more than one means a gap. Add explicit dependency edges. Then run Kahn's algorithm, but use...