✅ JavaScript || 👁 explanation of all cases ||  Easy to understand
\n\n# Complexity\n- Time complexity:\n     O(n^2)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:\n     O(n^2) \n Add your space complexity h
\n\n# Complexity\n- Time complexity:\n     O(n^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n     O(n^2) \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Explanation\ncreate (n-2,n-2) new empty matrix\niterate throw whole grid one time and each time check the current 3x3 matrix max number and save it in the new matrix\n\nHere are all the cases of given **Example 1**\n![00d.png](https://assets.leetcode.com/users/images/df321e29-d63b-4a49-9350-bd647aab5ec3_1669804099.747375.png)\n\n![01d.png](https://assets.leetcode.com/users/images/80857dd3-f0b7-41c8-b0a8-e11d08511759_1669804137.9130902.png)\n\n![10d.png](https://assets.leetcode.com/users/images/0ef37916-80fc-47dd-b860-78e6f1013115_1669804146.7263503.png)\n\n![11d.png](https://assets.leetcode.com/users/images/19ca117b-5858-4115-bbe3-a29dfe0b9d47_1669804152.7451894.png)\n\n# Code\n```\n/**\n * @param {number[][]} grid\n * @return {number[][]}\n */\nvar largestLocal = function(grid) {\n    // declare (n-2 x n-2) matrix\n   const matrix = new Array(grid.length -2).fill(0)\n                .map(() => new Array(grid[0].length-2).fill(0));\n    \n    for (let i=0; i< grid[i].length -2 ; i++){\n        for(let j=0; j<grid.length -2 ;j++){\n\n            //find the max in each 3x3 martix\n            matrix[i][j] = Math.max( \n                grid[i][j],     grid[i][j+1],   grid[i][j+2],\n                grid[i+1][j],  grid[i+1][j+1],  grid[i+1][j+2],\n                grid[i+2][j],  grid[i+2][j+1],  grid[i+2][j+2]\n                );\n            \n        }\n    }\n\n    return matrix;\n};\n```
['Matrix', 'JavaScript']