Amazon interview question

Coding question was on trees.