Pregunta de entrevista de Bloomberg

algorithm question about tree backtracking