Order Pending Transactions by Account Sequence Number
Last updated: November 29, 2026
Quick Overview
An account's next expected sequence number is known, and a client has submitted a batch of signed transactions tagged with sequence numbers, possibly out of order, with duplicates, gaps, and stale entries. Return which transactions can apply now in order, which are blocked behind a gap, which are stale, and the first missing sequence.
Ripple
November 29, 20260
0
0 solved
An account's next expected sequence number is known, and a client has submitted a batch of signed transactions tagged with sequence numbers, possibly out of order, with duplicates, gaps, and stale entries. Return which transactions can apply now in order, which are blocked behind a gap, which are stale, and the first missing sequence.
Sequence numbers are how the XRP Ledger prevents replay and orders an account's transactions, and a client or queueing service must reason about them constantly. This screen question checks hash map fluency and whether you ask the right clarifying questions about duplicates and stale entries before coding.
What the Interviewer Expects
- Clarify what to do with duplicate sequence numbers and sequences below the current one
- Use a dictionary keyed by sequence for O(1) lookups
- Walk forward from the current sequence to find the applicable run
- Report the first gap so the client knows what to resubmit
- Keep the output deterministic (sorted blocked list)
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 tickets, which let an account reserve sequence numbers out of order, change this?
- If two different transactions share a sequence, how should a real server pick one?
- How would you handle a transaction that fails with a fee-claimed result but still consumes its sequence?
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: current_seq (the next sequence the account expects) and a list of (seq, tx_id). Outputs: applicable (a consecutive run starting at current_seq), blocked (valid future sequences stuck...
High-Level Design
One pass to bucket the submissions: stale ones go straight to a list, the rest go into a dictionary keyed by sequence. Then walk s = current_seq, current_seq + 1, ... while s is in the dictionary,...