Pergunta de entrevista da empresa Bloomberg

Leetcode question regarding trees