Beats 50% Easy Brute Force⏪
\u2B06PLEASE UPVOTE IF IT HELPS\u2B06\n# Code\n\nclass Solution:\n    def resultGrid(self, image: List[List[int]], threshold: int) -> List[List[int]]:\n        
**\u2B06PLEASE UPVOTE IF IT HELPS\u2B06**\n# Code\n```\nclass Solution:\n    def resultGrid(self, image: List[List[int]], threshold: int) -> List[List[int]]:\n        regions = []\n        adj = []\n\n        def isvalid(i, j):\n            return 0 <= i < 3 and 0 <= j < 3\n\n        def helper(i, j):\n            temp = []\n            for k in range(i, i+3):  \n                temp0 = []\n                for o in range(j, j+3):  \n                    temp0.append(image[k][o])\n                temp.append(temp0)\n            regions = temp\n            moves = [(0,1),(-1,0),(0,-1),(1,0)]\n            ii=regions\n            for k in range(len(ii)):\n                for o in range(len(ii[0])):\n                    for dx, dy in moves:\n                        if isvalid(k+dx, o+dy):\n                            if abs(ii[k][o] - ii[k+dx][o+dy]) > threshold:\n                                break\n                    else:\n                        continue\n                    break\n                else:\n                    continue\n                break\n            else:\n                adj = ii\n\n                s = 0\n                for p in adj:\n                    s+=sum(p)\n                avg = s//9\n                for q in range(i,i+3):\n                    for w in range(j,j+3):\n                        if result[q][w]==[-1]:\n                            result[q][w] = [avg]\n                        else: result[q][w].append(avg)\n        result = []\n        for row in range(len(image)):\n            result.append([[-1]]*len(image[0]))\n\n        for i in range(len(image)-2):\n            for j in range(len(image[0])-2):\n                helper(i, j)\n        final= []\n        for row in range(len(image)):\n            final.append([0]*len(image[0]))\n        for i in range(len(image)):\n            for j in range(len(image[0])):\n                final[i][j] = sum(result[i][j])//len(result[i][j])\n        for i in range(len(image)):\n            for j in range(len(image[0])):\n                if final[i][j]==-1:\n                    final[i][j] = image[i][j]\n        return final\n\n\n```\n**\u2B06PLEASE UPVOTE IF IT HELPS\u2B06**
['Python3']