Easy30 pts
Cavity Map
An n×n grid of digits (depths). A cell is a cavity if: (1) not on border, (2) all 4 neighbors (up, down, left, right) have strictly smaller depth. Replace cavity cells with 'X'. Example: Grid: 1112 1912 1892 1234 Cell (1,1) has depth 9, neighbors: 1,1,1,1 (all < 9) → Cavity → Replace with X. Output: 1112 1X12 18X2 1234
Input
First line: n. Next n lines: strings of n digits each.
Output
Print the modified grid with 'X' in cavity positions.
Sample
4 1112 1912 1892 1234
Expected
1112 1X12 18X2 1234
Loading editor…
Output
No output yet. Run your code to see results.