Easy C++ Solution || Brute force
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    bool isregion(int startrow,int startcol,int endrow,int endcol,vector<vector<int>>& image,int &threshold)\n    {\n        int delrow[]={-1,0,1,0};\n        int delcol[]={0,1,0,-1};\n        for(int i=startrow;i<=endrow;i++)\n        {\n            for(int j=startcol;j<=endcol;j++)\n            {\n                for(int k=0;k<4;k++)\n                {\n                    int nrow=i+delrow[k];\n                    int ncol=j+delcol[k];\n                    \n                    if(nrow>=startrow && nrow<=endrow && ncol>=startcol && ncol<=endcol)\n                    {\n                        int diff=abs(image[i][j]-image[nrow][ncol]);\n                        if(diff > threshold) return false;\n                    }\n                }\n            }\n        }\n        return true;\n    }\n    \n    int average(int startrow,int startcol,int endrow,int endcol,vector<vector<int>>& image)\n    {\n         int sum=0;\n         for(int i=startrow;i<=endrow;i++)\n         {\n             for(int j=startcol;j<=endcol;j++)\n             {\n                 sum+=image[i][j];\n             }\n         }\n         int avg=sum/9;\n         return avg;\n    }\n    \n    vector<vector<int>> resultGrid(vector<vector<int>>& image, int threshold)\n    {\n        int total_row=image.size();\n        int total_col=image[0].size();\n        \n        map<pair<int,int>,vector<int>> mpp;\n        \n        for(int startrow=0,endrow=2;endrow<total_row;startrow++,endrow++)\n        {\n            for(int startcol=0,endcol=2;endcol<total_col;startcol++,endcol++)\n            {\n                if(isregion(startrow,startcol,endrow,endcol,image,threshold))\n                {\n                    int curravg=average(startrow,startcol,endrow,endcol,image);\n                    \n                    for(int i=startrow;i<=endrow;i++)\n                    {\n                        for(int j=startcol;j<=endcol;j++)\n                        {\n                            mpp[{i,j}].push_back(curravg);\n                        }\n                    }\n                }\n            }\n        }\n\n        for(auto &it: mpp)\n        {\n            int row=it.first.first;\n            int col=it.first.second;\n            vector<int> temp=it.second;\n\n            int sum=0;\n            int n=temp.size();\n            for(int i=0;i<n;i++)\n            {\n                sum+=temp[i];\n            }\n            int overallavg=sum/n;\n            image[row][col]=overallavg;\n        }\n        return image;  \n    }\n};\n```
['C++']