A greenhouse floor is tiled with an n x n grid of sensors, each reporting a positive integer reading. For every 3x3 block of adjacent sensors -- with its top-left corner at row i, column j, for every valid i and j -- determine the maximum reading recorded anywhere inside that block. Report the resulting grid of block maxima, which has (n-2) rows and (n-2) columns.
Print n-2 lines, each with n-2 space-separated integers. The entry at (0-indexed) row i, column j must equal the maximum sensor reading within the 3x3 block occupying rows i..i+2 and columns j..j+2 of the input grid.
Example 1
Input
3 1 2 3 4 9 5 6 7 8
Expected
9
Explanation
Since n=3, there is exactly one 3x3 block, covering the whole grid. The maximum value anywhere in the grid is 9 (at row 1, column 1), so the output is a single 1x1 grid containing 9.
Example 2
Input
4 1 1 1 1 1 5 1 1 1 1 9 1 1 1 1 1
Expected
9 9 9 9
Explanation
There are four 3x3 windows, with top-left corners at (0,0), (0,1), (1,0) and (1,1). The value 9 sits at row 2, column 2, which falls inside all four windows (each window spans rows [0,2] or [1,3] and columns [0,2] or [1,3], both of which include row/column 2). So every window's maximum is 9, giving the 2x2 output grid of all 9s.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →