I have the following method that is recursive and works pretty well but potentially can cause an StackOverflow exception, so I thought to convert this method to iterative one. H