Pregunta de entrevista de RouteOne

How would you solve this code challenge?