C++ | Recursion | Memoization | grid traversal
\nclass Solution {\npublic:\n    vector<vector<int>> dir={{0,-1},{0,1},{1,0},{-1,0}};\n    int dp[501][501][4];\n    int solve(int i,int j,int k,vector<vector<i
```\nclass Solution {\npublic:\n    vector<vector<int>> dir={{0,-1},{0,1},{1,0},{-1,0}};\n    int dp[501][501][4];\n    int solve(int i,int j,int k,vector<vector<int>> &grid){\n        int n = grid.size();\n        if(dp[i][j][k]!=-1) return dp[i][j][k];\n        int ni=i+dir[k][0];\n        int nj = j+dir[k][1];\n        if(ni<0||nj<0||ni>=n||nj>=n||grid[ni][nj]==0)\n            return 0;\n        return dp[i][j][k]=1+solve(ni,nj,k,grid);\n    }\n    int orderOfLargestPlusSign(int n, vector<vector<int>>& mines) {\n        vector<vector<int>> grid(n,vector<int>(n,1));\n        memset(dp,-1,sizeof(dp));\n        for(int i=0;i<mines.size();i++)\n            grid[mines[i][0]][mines[i][1]]=0;\n        int ans =0;\n        for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++){\n                if(grid[i][j]==1){\n                    ans=max(ans,1+min({solve(i,j,0,grid),solve(i,j,1,grid),solve(i,j,2,grid),solve(i,j,3,grid)})); \n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization']