Pergunta de entrevista da empresa Meta

Screening interview only: a technical coding challenge, medium to difficult involving trees. The question can be found in online training material or books but I didn't resolve it before.