Classic combination of matrix and DFS / BFS. Use a matrix “visited” of same size to flag visited nodes and stop duplicate path. Values or borders help decide heading or stopping.
Description