Pergunta de entrevista da empresa Jane Street

Question involving a tree structure and operations to find specified values.