C++ Brut Force, Easy to understand
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int dir[5] = {0, 1, 0, -1, 0};\n    int freq[500][500] = {0};\n    \n    \n    void fun(int i, int j, vector<vector<int>>& ans, vector<vector<int>>& image, int lim) {\n        int sum = 0;\n                 for(int l = i; l < i + 3; l++) {\n                    for(int k = j; k < j + 3; k++) {\n                        for(int d = 0; d < 4; d++) {\n                            int x = l + dir[d];\n                            int y = k + dir[d+1];\n                            if(x >= i && y >= j && x < i + 3 && y < j + 3) {\n                                if(abs(image[x][y] - image[l][k]) > lim) return;\n                            }\n                            // else return;\n                        }\n                        sum += image[l][k];\n                    }\n                }  \n        // cout << sum << " f " << endl;\n        sum /= 9;\n        \n        for(int l = i; l < i + 3; l++) {\n            for(int k = j; k < j + 3; k++) {\n                // if(ans[l][k] > 0) \n                ans[l][k] += sum;\n                freq[l][k]++;\n            }\n        }\n    }\n    \n    vector<vector<int>> resultGrid(vector<vector<int>>& image, int lim) {\n        int n = image.size(), m = image[0].size();\n        vector<vector<int>> ans(n, vector<int>(m, 0));\n        \n        \n        \n        for(int i = 0; i <= n - 3; i++) {\n            for(int j = 0; j <= m - 3; j++) {\n                // memset(vis, 0, sizeof(0));\n               fun(i, j, ans, image, lim);\n            }\n        }\n        \n        for(int i = 0; i < n; i++) {\n            for(int j = 0; j < m; j++) {\n                if(freq[i][j] > 0) {\n                    ans[i][j] /= freq[i][j];\n                    // if(ans[i][j] == 0) ans[i][j] = 1;\n                } else {\n                    if(ans[i][j] == 0) ans[i][j] = image[i][j];\n                }\n                \n            }\n            // cout << endl;\n        }\n        \n        return ans;\n    }\n};\n```
['C++']