Faster, Cheaper, Elegant Sliding Window Solution - Python✔️
Intuition\nMy initial thoughts were to avoid using nested loops by employing a sliding window approach to find the maximum value for each 3x3 submatrix horizont
# Intuition\nMy initial thoughts were to avoid using nested loops by employing a sliding window approach to find the maximum value for each 3x3 submatrix horizontally. Then, I planned to transpose the resulting matrix to apply the same sliding window vertically. Rather than implementing another sliding window for each column, I chose to transpose the matrix, perform the computation, and then transpose it back.\n\n\n\n# Complexity\n- Time complexity:$$O(n\xB2)$$\n\n# Code\n```python\nclass Solution:\n    def largestLocal(self, grid: List[List[int]]) -> List[List[int]]:\n        size, windowSize, max_horiz_matrix, resT = len(grid), 3, [], []\n\n        for row in grid:\n            max_horiz_matrix.append(self.max_sliding_window(row, windowSize))\n            \n        for row in self.transpose(max_horiz_matrix):\n            resT.append(self.max_sliding_window(row, windowSize))\n\n        return self.transpose(resT)\n    \n    def transpose(self, matrix):\n        return [[matrix[j][i] for j in range(len(matrix))] for i in range(len(matrix[0]))]\n\n    def max_sliding_window(self,nums, k):\n        result = []\n        window = deque()\n\n        for i in range(k):\n            while window and nums[i] >= nums[window[-1]]:\n                window.pop()\n            window.append(i)\n\n        for i in range(k, len(nums)):\n            result.append(nums[window[0]])\n            while window and window[0] <= i - k:\n                window.popleft()\n            while window and nums[i] >= nums[window[-1]]:\n                window.pop()\n            window.append(i)\n\n        result.append(nums[window[0]])\n\n        return result\n```
['Python3']