simple two pass solution with explanation
Intuition\n- We are using divide and conquer to solve this problem. \n- The idea is first find max for each column then find max for each row on grid obtained f
# Intuition\n- We are using divide and conquer to solve this problem. \n- The idea is first find max for each column then find max for each row on grid obtained from previos result\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- Get rowMax grid by taking max of 3 subsequent element. \n- We can use sliding window for this but window size is always 3 so we are taking 3 elements in each iteration and finding thier max\n- Repeat same operation but change row to column and set max value in result grid.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n*n) we are traversing grid twice\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n*n) needed for storing row max and result\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n\n```c++ []\nclass Solution {\npublic:\n    vector<vector<int>> largestLocal(vector<vector<int>>& g) {\n        int n = g.size();\n        vector<vector<int>> rowMax(n);\n        for(int i=0;i<n;i++) {\n            for(int j=0;j<(n-2);j++) {\n                int currMax = max(g[i][j], max(g[i][j+1], g[i][j+2]));\n                rowMax[i].push_back(currMax);\n            }\n        }\n\n        vector<vector<int>> res(n-2, vector<int>(n-2, 0));\n        for(int j=0;j<(n-2);j++) {\n            for(int i=0;i<(n-2);i++) {\n                int currMax = max(rowMax[i][j], max(rowMax[i+1][j], rowMax[i+2][j]));\n                res[i][j]=currMax;\n            }\n        }\n        return res;\n    }\n};\n```\n```go []\n\nfunc largestLocal(g [][]int) [][]int {\n\tn := len(g)\n\trowMax := make([][]int, n)\n\tfor i := 0; i < n; i++ {\n\t\trowMax[i] = make([]int, n-2)\n\t\tfor j := 0; j < n-2; j++ {\n\t\t\tcurrMax := max(g[i][j], max(g[i][j+1], g[i][j+2]))\n\t\t\trowMax[i][j] = currMax\n\t\t}\n\t}\n\n\tres := make([][]int, n-2)\n\tfor i := 0; i < n-2; i++ {\n\t\tres[i] = make([]int, n-2)\n\t\tfor j := 0; j < n-2; j++ {\n\t\t\tcurrMax := max(rowMax[i][j], max(rowMax[i+1][j], rowMax[i+2][j]))\n\t\t\tres[i][j] = currMax\n\t\t}\n\t}\n\treturn res\n}\n```\n```python []\nclass Solution(object):\n    def largestLocal(self, g):\n        n = len(g)\n        row_max = []\n        for i in range(n):\n            row_max.append([])\n            for j in range(n - 2):\n                curr_max = max(g[i][j], g[i][j + 1], g[i][j + 2])\n                row_max[i].append(curr_max)\n\n        res = [[0] * (n - 2) for _ in range(n - 2)]\n        for j in range(n - 2):\n            for i in range(n - 2):\n                curr_max = max(row_max[i][j], row_max[i + 1][j], row_max[i + 2][j])\n                res[i][j] = curr_max\n        return res\n```\n
['C++']