Pergunta de entrevista da empresa Amazon

Coding question of tree and graph