Teamnet interview question

Implement an optimized loop for different problems.