Leap Tools Interview Question

Implement an algorithm according to these specifications.