Grid
Word Progress

Phase

-

Current Cell

-

Matched

-

Cells Explored

0
DFS Path
Empty
Click "Step" or "Play" to start the visualization
Default
Scanning
DFS Path
Current
Found
Backtrack
Python Code
def exist(board, word):
    for i in range(rows):
        for j in range(cols):
            if dfs(i, j, 0): return True
    return False
def dfs(r, c, k):
    if k == len(word): return True
    if out_of_bounds or board[r][c] != word[k]:
        return False
    board[r][c] = '#' # mark visited
    found = dfs(r±1,c,k+1) or dfs(r,c±1,k+1)
    board[r][c] = word[k] # restore
    return found