Google Interview Question

Trees based on meduim problem