title: Time and space complexity of recursion DFS when finding path in a maze
body: <p>The question is : a man is looking for a target(which is marked as 9) in a 2D array, where 0 represents walls and 1 represents roads. The method should find if the man can find the target or not. </p>
  
  <p>I came up with the solution using DFS easily, but got stuck when trying to find out the time and space complexity of my code.</p>
  
  <pre><code>public boolean find(int[][] grid) {
      if(grid == null || grid.length == 0 || grid[0].length == 0 || grid[0][0] == 0) return 0;
      return helper(grid,0,0);    
  }
  
  private boolean helper(int[][] grid,int x, int y) {
      if(x &gt;= 0 &amp;&amp; x &lt; grid.length &amp;&amp; y &gt;= 0 &amp;&amp; y &lt; grid[0].length) {
          if(grid[x][y] == 0) return false;
          else if(grid[x][y] == 9) return true;
          else if(grid[x][y] == 1) {
              grid[x][y]=2;
              return helper(grid,x,y-1) || helper(grid,x+1,y) || helper(grid,x,y+1) || helper(grid,x-1,y);
          }
          else return false;
      }
      else return false;
  }
  </code></pre>
  
  <p>I think the time and space complexity is O(mn), but I am not sure.</p>