Pergunta de entrevista da empresa Google

leetcode tree question, one question never seen before.