Sliding window solution
Approach\n Describe your approach to solving the problem. \nTo calculate the maximum 3x3 matrix for each row, you can use a deque structure and store three maxi
# Approach\n<!-- Describe your approach to solving the problem. -->\nTo calculate the maximum 3x3 matrix for each row, you can use a deque structure and store three maximum values for each column in it. This way, for the next column, you can avoid recalculating already calculated maximums. It\'s sufficient to remove the left element from the deque and add the maximum for the column that hasn\'t been considered yet.\n\nThis solution is slightly better than the trivial idea of calculating the maximum from the 3x3 matrix for each cell.\n\n\n# Complexity\n- Time complexity: $O(N^2)$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $O(N^2)$ additional memory for responce.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> largestLocal(vector<vector<int>> &grid) {\n        auto size = grid.size();\n        auto result = vector(size - 2, vector<int>(size - 2));\n        for (size_t row = 0; row < size - 2; ++row) {\n            std::deque<int> deque;\n            deque.push_back(std::max(grid[row][0], std::max(grid[row + 1][0], grid[row + 2][0])));\n            deque.push_back(std::max(grid[row][1], std::max(grid[row + 1][1], grid[row + 2][1])));\n            deque.push_back(std::max(grid[row][2], std::max(grid[row + 1][2], grid[row + 2][2])));\n\n            result[row][0] = *std::max_element(deque.begin(), deque.end());\n\n            for (size_t col = 1; col < size - 2; ++col) {\n                deque.pop_front();\n                deque.push_back(std::max(grid[row][col + 2], std::max(grid[row + 1][col + 2], grid[row + 2][col + 2])));\n\n                result[row][col] = *std::max_element(deque.begin(), deque.end());\n            }\n        }\n        return result;\n    }\n};\n\n```\n\nMost of my solutions are in [C++](https://github.com/drgavrikov/leetcode-cpp) and [Kotlin](https://github.com/drgavrikov/leetcode-jvm) on my [Github](https://github.com/drgavrikov).
['Sliding Window', 'Matrix', 'C++']