Iterative and recursive solutions