Easy Python Brute-Force Solution
Code\n\nclass Solution:\n    def resultGrid(self, image: List[List[int]], k: int) -> List[List[int]]:\n        rows, cols, regionId, res = len(image), len(image
# Code\n```\nclass Solution:\n    def resultGrid(self, image: List[List[int]], k: int) -> List[List[int]]:\n        rows, cols, regionId, res = len(image), len(image[0]), 0, image.copy()\n        cell_region_map, regionAvg = defaultdict(lambda: []), defaultdict(lambda: 0)\n        moves = [(-1, 0), (1, 0), (0, 1), (0, -1)]\n\n        is3x3 = lambda sub: bool((len(sub), len(sub[0])) == (3 ,3))\n        isInside = lambda i, j: bool(0 <= i < 3 and 0 <= j < 3)\n\n        def isRegion(sub):\n            for i in range(3):\n                for j in range(3):\n                    for move in moves:\n                        x, y = i + move[0], j + move[1]\n                        if isInside(x, y):\n                            if abs(sub[i][j] - sub[x][y]) > k:\n                                return False\n            return True\n        \n        for i in range(rows):\n            for j in range(cols):\n                sub = [row[j : j + 3] for row in image[i : i + 3]]\n                if is3x3(sub):\n                    if isRegion(sub):\n                        regionAvg[regionId] = sum([sum(row) for row in sub])//9\n                        for x in range(3):\n                            for y in range(3):\n                                cell_region_map[(i + x, j + y)].append(regionId)\n                        regionId += 1\n        \n        for i in range(rows):\n            for j in range(cols):\n                n = len(cell_region_map[(i, j)])\n                if n > 0:\n                    res[i][j] = sum([regionAvg[region] for region in cell_region_map[(i, j)]])//n\n        \n        return res\n    \n    \n    \n    \n    \n    \n    \n    \n    \n    \n    \n```
['Hash Table', 'Matrix', 'Python3']