Added iterative solution to the problem