Merge Primary and Replica Transaction Lists Into One Deduplicated List
Last updated: November 29, 2026
Quick Overview
Two singly linked lists of balance transactions are each sorted by `(created, id)`, and some transactions appear in both. Merge them in place into one sorted linked list where every transaction id appears exactly once.
Stripe
November 29, 20260
0
0 solved
Two singly linked lists of balance transactions are each sorted by `(created, id)`, and some transactions appear in both. Merge them in place into one sorted linked list where every transaction id appears exactly once.
During a datastore migration at Stripe, reads may come from both an old primary and a new replica, and tooling must combine them without double-counting balance transactions. The interviewer checks pointer handling with a dummy head, correct tie-breaking on a composite key and that duplicates are dropped without allocating new nodes.
What the Interviewer Expects
- Use a dummy head and a tail pointer to splice nodes without special cases
- Compare on the full `(created, id)` key, not just the timestamp
- Skip a node whose key equals the last appended key
- Terminate the merged list explicitly so dropped nodes do not leak back in
- Keep it O(1) extra space by reusing nodes
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
- What if the same id appears with different amounts on the two sides?
- How would you merge k lists instead of two?
- How would you do this if the lists were too large for memory and streamed from disk?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Nodes have created, id, amount and next. Both inputs are sorted ascending by (created, id) and may contain duplicates of each other or within themselves. Return the head of the merged list....
High-Level Design
Classic two-pointer merge with a twist: before appending the chosen node, compare its key to the key of the last node appended. Because both inputs are sorted by the same key, any duplicate must arriv...