Brute Force Approach.......🍁
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 {\n    public int[][] resultGrid(int[][] image, int threshold) {\n        int m = image.length;\n        int n = image[0].length;\n        int region[][] = new int[m-2][n-2];\n        int res[][] = new int[m][n];\n        int count[][] = new int[m][n];\n       \n        for(int i=0; i<=m-3; i++) {\n            for(int j=0; j<=n-3; j++) {\n                boolean isRegions = isRegion(image, i, j, threshold);\n                int sum=0;\n                for(int r=i; r<i+3; r++) {\n                    for(int c=j; c<j+3; c++) {\n                        if(isRegions) {\n                            sum+=image[r][c];\n                            count[r][c]+=1;\n                        }else {\n                            if(count[r][c]==0) {\n                                res[r][c]=-1;\n                            } \n                        }\n                    }\n                }\n                region[i][j]=sum/9;\n                if(isRegions) {\n                    for(int r=i; r<i+3; r++) {\n                        for(int c=j; c<j+3; c++) {\n                            if(res[r][c]==-1) {\n                                res[r][c]=0;\n                            }\n                            res[r][c]+=region[i][j];\n                        }\n                    }\n                }\n                \n            }\n        }\n       \n        for(int i=0; i<m; i++) {\n            for(int j=0; j<n; j++) {\n                res[i][j] = res[i][j]==-1 ? image[i][j] : res[i][j]/count[i][j];\n            }\n        }\n        return res ;\n\n    }\n    public boolean isRegion(int[][] image, int startRow, int startCol, int threshold) {\n        int endRow = startRow+2;\n        int endCol = startCol+2;\n\n        for(int i=startRow; i<=endRow; i++) {\n            for(int j=startCol; j<=endCol; j++) {\n                if(i-1>=startRow && Math.abs(image[i][j]-image[i-1][j])>threshold) {\n                    return false;\n                }\n                if(i+1<=endRow && Math.abs(image[i][j]-image[i+1][j])>threshold) {\n                    return false;\n                }\n                if(j-1>=startCol && Math.abs(image[i][j]-image[i][j-1])>threshold) {\n                    return false;\n                }\n                if(j+1<=endCol && Math.abs(image[i][j]-image[i][j+1])>threshold) {\n                    return false;\n                }\n            }\n        }\n        return true;\n\n    }\n    \n}\n```
['Brainteaser', 'Python', 'C++', 'Java']