solve it both recursively and iteratively.