Largest Local Values in a Matrix (Easy Solution with Detailed Explanation)
Intuition\n Describe your first thoughts on how to solve this problem. \nCreate a submatrix for each position, calculate the max element and store it in result 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCreate a submatrix for each position, calculate the max element and store it in result matrix\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialize n with length of grid.\n2. Initialize result matrix res of n-2 size and with all zero value.\n3. Run a for loop from i = 0 to n-2 this is for the row number of result matrix : \n    1. Run a for loop from j = 0 to n-2 this is for the column number of result matrix : \n        1. Now for each i,j position in result matrix we will form a 3*3 submatrix from the original grid matrix and check for the max value for that position\n        2. Run a for loop from r = i to i+3 for rows in the submatirx :\n            1. Run a for loop from c = j to j+3 for columns in the submatrix: \n                1. Find the max value and store it in i,j position in res\n4. Return res\n\n# Complexity\n- Time complexity : O(n^2) becuase the last two loops will always run for 9 times\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity : O(n^2) for result matrix\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution(object):\n    def largestLocal(self, grid):\n        """\n        :type grid: List[List[int]]\n        :rtype: List[List[int]]\n        """\n        n = len(grid)\n        res = [[0]*(n-2) for _ in range(n-2)]\n        for i in range(n-2):\n            for j in range(n-2):\n                for r in range(i,i+3):\n                    for c in range(j,j+3):\n                        res[i][j] = max(res[i][j],grid[r][c])\n        return res\n```
['Python']