added iterative and recursive solutions