CityGrid Media interview question

Converting a recursive function to non-recursive version.