C++ Easy DFS+Memoization
```\nclass Solution {\npublic:\n    vector> dp;\n    \n    bool isExit(int i,int j,int m,int n,vector& entrance)\n    {\n        //Exit lies at the edges of the
```\nclass Solution {\npublic:\n    vector<vector<long int>> dp;\n    \n    bool isExit(int i,int j,int m,int n,vector<int>& entrance)\n    {\n        //Exit lies at the edges of the maze and entrance can\'t be the exit\n        if(i!=entrance[0]||j!=entrance[1])\n        {\n            if(i==0||j==0||i==m-1||j==n-1)\n            return true;\n        }\n        \n        return false;\n    }\n    int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n        \n        int m = maze.size();\n        int n = maze[0].size();\n        \n        dp.resize(m,vector<long int>(n,-1));\n        int i = entrance[0];\n        int j = entrance[1];\n        \n       \n       \n        long int res = dfs(i,j,m,n,maze,entrance);\n                \n        \n        //If we are able to reach the exit then print the minumum no. of steps else -1\n        return res>=INT_MAX ? -1 : res;\n        \n       \n        \n    }\n    \n    long int dfs(int i,int j,int m,int n,vector<vector<char>>& maze,vector<int>& entrance)\n    {\n        if(i<0||j<0||i>m-1||j>n-1||maze[i][j]==\'+\')\n            return INT_MAX;//since we can\'t reach such cells\n        \n        if(dp[i][j]!=-1)\n            return dp[i][j];\n        \n        if(isExit(i,j,m,n,entrance))\n        {\n            \n            return dp[i][j] = 0;\n        }\n        \n        maze[i][j] = \'+\'; //mark this as visited\n        \n        //The order of visiting the neighbouring cells is fixed\n\t\tlong int temp = 1+min({dfs(i+1,j,m,n,maze,entrance), dfs(i-1,j,m,n,maze,entrance),dfs(i,j+1,m,n,maze,entrance),dfs(i,j-1,m,n,maze,entrance)});\n        \n        maze[i][j] = \'.\';//dfs call ended for cell(i,j)\n        \n        return dp[i][j] = temp;\n    }\n};
[]