Pergunta de entrevista da empresa Leap Tools

Implement an algorithm according to these specifications.