Amazon Interview Question

Coding question was on trees.