Pregunta de entrevista de Meta

Hard problem related to recursion on a tree