Pregunta de entrevista de Amazon

some medium-difficulty binary tree problem