Amazon Interview Question

Leet code medium problem which required knowledge of trees