Merkle Interview Question

Asked to write sql queries for given usecase