In a generic DFS problem, we look for a starting point and from there we look for an end target position to reach.

Similarly, In the matrix-related problems, we look for any cell as a starting point and from there we look for any end target position by following the conditions of given problem statement.

 

 

Similar Problems:

Some DFS questions that you could try with the template to have a better understanding : ( with increasing difficulty )

  1. https://yellowcoding.com/search-a-word-in-a-2d-matrix-of-characters
  2. https://yellowcoding.com/regions-cut-by-slashes/
  3. https://yellowcoding.com/longest-increasing-path-in-a-matrix-dfs-approach/