Amazon interview question

Leet code medium problem which required knowledge of trees