Find Diverging Ledger Batches by Comparing Two Merkle Trees

Last updated: November 29, 2026

Quick Overview

Two systems each hold the same sequence of ledger batches. Build a Merkle tree (a binary tree of SHA-256 hashes) over each side's batch hashes and return the indices of batches that differ, descending only into subtrees whose hashes disagree.

Stripe
Coding & Algorithms
Software Engineer
Stripe
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Two systems each hold the same sequence of ledger batches. Build a Merkle tree (a binary tree of SHA-256 hashes) over each side's batch hashes and return the indices of batches that differ, descending only into subtrees whose hashes disagree.

Stripe reconciles its internal ledger against copies held by other services and partners, and comparing full datasets every time is expensive. A Merkle tree turns that into a few hash comparisons, and the interviewer checks that you can build the binary tree, handle odd node counts and prune matching subtrees recursively.

What the Interviewer Expects
  • Build the tree bottom-up, pairing nodes level by level
  • Define a rule for odd counts (promote the last node unchanged) and apply it on both sides
  • Store each node's leaf range so differences map back to batch indices
  • Recurse only into children whose hashes differ
  • Explain why the cost is proportional to the number of differences times tree height
Key Topics to Cover
binary trees
recursion
hashing
Merkle trees
reconciliation
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 two services run this over the network without sending whole trees?
  • What if one side has extra batches appended at the end?
  • Why should leaf and internal hashes use different prefixes?
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

Input: two equal-length lists of batch payload strings. Output: sorted indices where the batches differ. Both sides build their trees with the same deterministic rules....

High-Level Design

Leaves hash "L" + payload; internal nodes hash "N" + left.hash + right.hash. Domain separation prevents a leaf from ever colliding with an internal node. When a level has an odd count, the last no...


Submit Your Answer
Markdown supported

Related Questions