c++ || 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    vector<vector<int>> resultGrid(vector<vector<int>>& im, int t) {\n        \n        int n = im.size();\n        int m = im[0].size();\n\n        vector <vector <int>> ans = im;\n        \n        vector <vector<vector<int>>> anss(n,vector<vector<int>>(m));\n         \n        for ( int i=0; i<n-2; i++ ) {\n            for ( int j=0; j<m-2; j++ ) {\n\n                int sum = 0;\n                bool f = 0;\n\n                for ( int x=i; x<i+3; x++ ) {\n                    for ( int y=j; y<j+3; y++ ) {\n\n                        if ( x>i && abs(im[x][y]-im[x-1][y]) > t ) {\n                            f = 1;\n                        }\n\n                        if ( y>j && abs(im[x][y]-im[x][y-1]) > t ) {\n                            f = 1;\n                        }\n\n                        sum += im[x][y];\n                    }\n                }\n\n                if ( f ) {\n                    continue;\n                }\n\n                for ( int x=i; x<i+3; x++ ) {\n                    for ( int y=j; y<j+3; y++ ) {\n                        anss[x][y].push_back(sum/9);\n                    }\n                }\n            }\n        }\n\n        for ( int i=0; i<n; i++ ) {\n            for ( int j=0; j<m; j++ ) {\n\n                if ( anss[i][j].size() ) {\n\n                    int sum = 0;\n                    for ( auto x : anss[i][j] ) {\n                        sum += x;\n                    }\n\n                    ans[i][j] = sum/int(anss[i][j].size());\n                }\n            }\n        }\n\n        return ans;\n    }\n};\n```
['C++']