Pregunta de entrevista de Microsoft

How would you solve this python problem.