Credit Blockchain Deposits Safely Across Chain Reorganizations

Last updated: November 29, 2026

Quick Overview

Process an arrival-ordered stream of blocks, where a block at an already-seen height replaces that height and everything above it, and maintain which deposits to watched addresses are credited (at least K confirmations), which are pending, and which were credited and must be reverted because a reorg orphaned them.

Gemini
Coding & Algorithms
Software Engineer
Gemini
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Process an arrival-ordered stream of blocks, where a block at an already-seen height replaces that height and everything above it, and maintain which deposits to watched addresses are credited (at least K confirmations), which are pending, and which were credited and must be reverted because a reorg orphaned them.

Gemini credits customer deposits on many chains, and Hyperdrive-style wallet infrastructure must cope with forks where blocks are replaced. This onsite problem tests careful state management on a chain, the confirmation rule, and how a candidate reasons about the cost of crediting too early.

What the Interviewer Expects
  • Represent the tracked chain as a contiguous array from a base height
  • Validate parent hashes to detect gaps instead of silently accepting forks
  • On a reorg, drop the orphaned suffix and identify credited transactions that vanished
  • Do not revert a transaction that reappears in the new branch
  • Credit only after K confirmations, counting the containing block as one
  • Explain why K differs by chain and what the business does with a reverted credit
Key Topics to Cover
Blockchain
Reorg Handling
State Machine
Confirmations
Idempotency
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you choose K per asset, and could it depend on deposit size?
  • How do you handle a reorg deeper than your tracked window?
  • What should happen to a user who already traded or withdrew a reverted deposit?
  • How would you make crediting idempotent across a restart of this service?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Blocks arrive as (height, hash, parent_hash, txs); txs are (txid, address, amount). Height h with tip T has T - h + 1 confirmations. Credit a watched deposit once it reaches K. If a later block ...

High-Level Design

chain[i] is the block at height base + i. A new block at index idx must link to chain[idx-1] by hash; otherwise we are missing part of a fork and must fetch it rather than guess. If `idx < len...


Submit Your Answer
Markdown supported

Related Questions