Leap Tools interview question

Implement an algorithm according to these specifications.