Pregunta de entrevista de Apple

How would you code a solution