Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-165

Merkle Root

Problem

Compute the Merkle root of four integer leaves using the pairing hash h(a, b) = (a * 1000003 + b) mod 2^32. The root is h(h(l0, l1), h(l2, l3)). Return the integer root.

Hint

Changing any leaf changes every hash on its path to the root.

Test cases

case 1
in: [[1,2,3,4]]
expected: 3578587356
case 2
in: [[0,0,0,0]]
expected: 0
case 3
in: [[1,1,1,1]]
expected: 3575587344
case 4
in: [[10,20,30,40]]
expected: 1426135192
Starter codePython
def merkle_root(leaves):
    # Your code here
    pass

4 test cases · run your code against them in the editor