Pregunta de entrevista de Amazon

Coding question was on trees.