Just was wondering how to integrate the floodfill with the stack.I guess it will get rid of recursion problem. You mean read all the elements of the array to a stack and then push and pop based on conditions?