Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

board =
word =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Try every cell as a start and DFS in 4 directions matching characters.

Approach

Backtracking DFS:

  • If current cell matches word[i], mark visited (temporary overwrite), explore neighbors for i+1, then restore.

Why it works

A valid path corresponds to a simple path in the grid; backtracking explores all possibilities without revisiting cells.

Code
Loading...
Complexity
Time: O(mn * 4^L) worst-case
Space: O(L)
Solution
Updated: 2026-02-23

Idea

Try every cell as a start and DFS in 4 directions matching characters.

Approach

Backtracking DFS:

  • If current cell matches word[i], mark visited (temporary overwrite), explore neighbors for i+1, then restore.

Why it works

A valid path corresponds to a simple path in the grid; backtracking explores all possibilities without revisiting cells.

Code
Loading...
Complexity
Time: O(mn * 4^L) worst-case
Space: O(L)