Adding non-recursive solution