Google Interview Question

Python coding problem about trees