Pregunta de entrevista de Freelancer

how can solve this problem? and create loop