Pregunta de entrevista de Leap Tools

Implement an algorithm according to these specifications.