Pregunta de entrevista de IntegraFEC

How would you solve this programming problem?