Cursor·Software Engineer·Technical Phone Screen
- Implement a Merkle tree from scratch given a list of data blocks. You need to support building the tree, returning the root hash, generating an inclusion proof for a leaf at a given index, and verifying that proof.
- How do you handle an odd number of leaves when building the Merkle tree?
- What hash function would you choose and how would you protect against second-preimage attacks in a Merkle tree?
- What is the time and space complexity for building the tree, generating a proof, and verifying a proof?
“I started with the build function and got through it okay, hashing leaves then pairwise hashing up.”