Pregunta de entrevista de Qualcomm

Coding question related to trees