Pregunta de entrevista de Didlake

How would you implement the solution?