Iterative Python Solution
seems the solutions are missing iterative approach.\nWe use stack to do dfs and also keep backtrack state to remove coordinates.\nThe idea is that after we visi
seems the solutions are missing iterative approach.\nWe use stack to do dfs and also keep `backtrack` state to remove coordinates.\nThe idea is that after we visit a node, we add a backtracking node to remove the node if we ever come back to the current stack level.\n\n```\nclass Solution(object):\n    def neighbors(self, board, r, c):\n        directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n        nbs = []\n        for d in directions:\n            nr = r + d[0]\n            nc = c + d[1]\n            if (0 <= nr < len(board)) and (0 <= nc < len(board[nr])):\n                nbs.append((nr, nc))\n        return nbs\n    \n    def exist(self, board, word):\n        """\n        :type board: List[List[str]]\n        :type word: str\n        :rtype: bool\n        """\n        q = list()\n\t\t\t\t\n        for r in range(len(board)): # find starting points\n            for c in range(len(board[r])):\n                if board[r][c] == word[0]:\n                    q.append((r, c))\n                    \n        for (r, c) in q:\n            visited = set()\n            stack = list()\n            stack.append((r, c, 0, False)) # regular forward moving node\n            while stack:\n                cr, cc, i, backtrack = stack.pop()\n                if backtrack:\n                    visited.remove((cr, cc))\n                    continue\n                    \n                visited.add((cr, cc))\n                stack.append((cr, cc, i, True)) # add backtracking node\n                if i == (len(word) - 1):\n                    return True\n            \n                for nr, nc in self.neighbors(board, cr, cc):\n                    if (nr, nc) in visited:\n                        continue\n                    if board[nr][nc] == word[i + 1]:\n                        stack.append((nr, nc, i + 1, False)) # forward-moving node\n            \n        return False\n```
[]