C++ brute force easy
Intuition\n Describe your first thoughts on how to solve this problem. \n\nCheck for each 3*3 grid\n# Approach\n Describe your approach to solving the problem. 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nCheck for each 3*3 grid\n# Approach\n<!-- Describe your approach to solving the problem. -->\nbrute force break problem into smaller tasks.\nIt will help in implementation\n# Complexity\n- Time complexity:\n- O(N^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N^2)\n\n# Code\n```\nclass Solution {\npublic:\n    \n    bool checkCell(int row, int x, int col, int y, vector<vector<int>> &image, int threshold){\n        \n        int curXCell = row + x;\n        int curYCell = col + y;\n                \n        for(int i = -1; i<=1; i++){\n            for(int j = -1; j<=1; j++){\n                int curI = curXCell + i;\n                int curJ = curYCell + j;\n                \n                if((abs(i)!=abs(j)) and (curI>=row and curI<(row+3)) and (curJ>=col and curJ<(col+3))){                    \n                    if(abs(image[curXCell][curYCell] - image[curI][curJ])>threshold){\n                        return false;\n                    }\n                }\n            }\n        }\n        return true;\n    }\n    \n    void fillAns(int r, int c, vector<vector<int>> &image, vector<vector<int>> &cells, int threshold, vector<vector<int>> &ans){\n        int calSum = 0;\n        bool exists = false;\n        \n        for(int i = 0; i < 3; i ++){\n            for(int j = 0; j < 3; j ++){\n                if(!checkCell(r, i, c, j, image, threshold)){\n                    return;\n                }\n                calSum+=image[r+i][c+j];\n            }\n        }\n        exists = true;\n        calSum /= 9;\n        \n        for(int i = 0; i < 3; i++){\n            for(int j=0; j < 3; j++){\n                if(exists){\n                    cells[r+i][c+j]++;\n                }\n                    ans[r+i][c+j] = (ans[r+i][c+j] + calSum);\n            }\n        }\n    }\n    \n    vector<vector<int>> resultGrid(vector<vector<int>>& image, int threshold) {\n        \n        vector<vector<int>> ans(image.size(), vector<int>(image[0].size(), 0));\n        vector<vector<int>> cells(image.size(), vector<int>(image[0].size(), 0));\n            \n        for(int i=0; i<image.size(); i++){\n            for(int j=0; j<image[0].size(); j++){\n                if((i+2<image.size()) and (j+2 < image[0].size()))\n                fillAns(i, j, image, cells, threshold, ans);\n            }\n        }\n        \n        for(int i=0; i<image.size(); i++){\n            for(int j=0; j<image[0].size(); j++){\n                if(!cells[i][j]){\n                    ans[i][j] = image[i][j];\n                }\n                else{\n                    ans[i][j]/=cells[i][j];\n                }\n            }\n        }\n        \n        return ans;\n    }\n};\n\n// [[0,0,0,6],\n// [0,0,0,6],\n// [0,0,0,6]]\n\n\n```
['C++']