Pregunta de entrevista de Appian

How would you code this solution