m × n matrix pixels, where pixels[i][j] is a brightness from 0 to 255. You also get a number tolerance.
A **tile** is any 3 × 3 square inside the image. A tile is **even** if every two pixels inside it that share a side differ in brightness by at most tolerance. The average of an even tile is the sum of its nine pixels divided by 9, rounded down.
Build a new matrix of the same size:
- a pixel that lies in no even tile keeps its value;
- otherwise its new value is the mean of the averages of all even tiles containing it, rounded down. The tile averages are taken already rounded.
Tiles may overlap, and one pixel can belong to several of them.pixels=[[10, 12, 11, 40], [11, 13, 12, 41], [12, 14, 13, 42]], tolerance=2 → [[12, 12, 12, 40], [12, 12, 12, 41], [12, 12, 12, 42]]
The left 3 × 3 tile is smooth: neighbouring pixels differ by at most 2, and its average is 108 // 9 = 12. The right tile has a jump from 11 to 40, so it doesn't count. Column 3 is covered by no smooth tile and stays as it was.
pixels=[[0, 0, 0], [0, 9, 0], [0, 0, 0]], tolerance=8 → [[0, 0, 0], [0, 9, 0], [0, 0, 0]]
The only tile isn't smooth (9 differs from its neighbours by 9 > 8), so the image stays the same.
pixels=[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]], tolerance=1 → [[2, 2, 2, 3], [2, 2, 2, 3], [2, 2, 2, 3]]
Both tiles are smooth, with averages 2 and 3. The middle columns are covered by both: (2 + 3) // 2 = 2.
pixels=[[10, 12, 11, 40], [11, 13, 12, 41], [12, 14, 13, 42]], tolerance=2
[[12, 12, 12, 40], [12, 12, 12, 41], [12, 12, 12, 42]]
Run checks the first 3 tests in your browser. Submit checks all 93 tests on the server, hidden ones included.