You are given a rectangular grid of numbers, represented as grid.
Your task is to identify groups of three or more identical, adjacent numbers in a row or column within the grid and modify them by setting all numbers in such groups to 0.
Note that:
Return the modified grid.
[ [1, 1, 1, 2], [1, 2, 2, 3], [3, 3, 2, 1] ]
[ [0, 0, 0, 2], [1, 2, 2, 3], [3, 3, 2, 1] ]
The top row has three adjacent '1's. This group is zeroed out. The '1' in the 2nd column is not part of the group.
[ [7, 2, 7, 2], [7, 7, 7, 7], [3, 3, 7, 7] ]
[ [7, 2, 0, 2], [0, 0, 0, 0], [3, 3, 0, 7] ]
The 7's in the 3rd column are zeroed out along with the 7's in the 2nd row.
[ [7, 3, 3, 3], [7, 5, 7, 7], [2, 2, 2, 7] ]
[ [7, 0, 0, 0], [7, 5, 7, 7], [0, 0, 0, 7] ]
The 3's in the first row are zeroed out, along with the 2's in the last row.
[ [1, 1, 1, 2], [1, 2, 2, 3], [3, 3, 2, 1] ]
[ [0, 0, 0, 2], [1, 2, 2, 3], [3, 3, 2, 1] ]