Solves Problem #9 - Needs Optimization