C++  clean code using 4 matrices
C++\nclass Solution {\npublic:\n  int orderOfLargestPlusSign(int N, vector<vector<int>>& mines) {\n    vector<vector<int>> grid(N,vector<int> (N,1));\n    vecto
```C++\nclass Solution {\npublic:\n  int orderOfLargestPlusSign(int N, vector<vector<int>>& mines) {\n    vector<vector<int>> grid(N,vector<int> (N,1));\n    vector<vector<int>> left(N,vector<int> (N,1)), right(N,vector<int> (N,1)), up(N,vector<int> (N,1)), down(N,vector<int> (N,1));\n\n    int ans = 0;\n    for(auto& mine:mines) grid[mine.front()][mine.back()] = 0;\n    for(int i = 0; i < N; i++){\n      for(int j = 0; j < N; j++)\n        if(j == 0) left[i][j] = grid[i][j];\n        else left[i][j] = grid[i][j] == 0 ?0: left[i][j-1] + 1;\n      for(int j = N - 1; j >= 0; j--)\n        if(j == N -1) right[i][j] = grid[i][j];\n        else right[i][j] = grid[i][j] == 0 ?0: right[i][j+1] + 1;\n    }\n    for(int j = 0; j < N; j++){\n      for(int i = 0; i < N; i++)\n        if( i == 0) up[i][j] = grid[i][j];\n        else up[i][j] = grid[i][j] == 0? 0: up[i - 1][j] + 1;\n      for(int i = N-1; i >=0; i--)\n        if(i == N - 1) down[i][j] = grid[i][j];\n        else down[i][j] = grid[i][j] == 0? 0: down[i+1][j] + 1;\n    }\n    for(int i = 0; i < N; i++)\n      for(int j = 0; j < N; j++)\n        grid[i][j] =min( min(up[i][j], down[i][j]), min(left[i][j],right[i][j]));\n\n\n    for(int i = 0; i < N; i++)\n      for(int j = 0; j < N; j++)\n        ans = max(ans, grid[i][j]);\n    return ans;\n  }\n};\n\n```
[]