Code ensamble (transversing tree)

Solution link. Why my solution is giving tle please help