Practice · 4 of 5
Neighbor counting
CHALLENGE
Difficulty: intermediate+25 XP
Implement int countNeighbors(int[][] grid, int row, int col, int value): how many orthogonal neighbors (up/down/left/right) equal value. Guard each direction independently — corners have 2, edges 3, interior 4.
Press Submit to check your solution.
Back to lesson: Practice: 2D array lab