Problem. Given an m × n grid of letters and a word, return whether the word can be formed by a path of cells that
are horizontally or vertically adjacent, using each cell at most once.
A B C E
S F C S "ABCCED" → True "SEE" → True "ABCB" → False (would reuse B)
A D E E
This is backtracking on a grid: the choices at each step are the four neighbours, and the "used" set is the path itself. The search space is huge (4 · 3^(L−1) paths per starting cell for a word of length L), so everything depends on pruning early.
ML context. Grids are images, maps and attention matrices. The same depth-first search with a visited mark finds connected regions: blobs in a segmentation mask, connected components in an occupancy grid, clusters of active cells in a feature map (Change B). There, the depth can reach the number of pixels, so the recursion must become an explicit stack.