Problem Statement | |||||||||||||
Consider a rectangular grid of cells that is given by a String[] grid. A cell marked with a 'X' character denotes an occupied cell, and a cell marked with a '.' character denotes an empty cell. We say that two cells are orthogonal neighbors if they share a common side, and they are diagonal neighbors if they are adjacent to one another diagonally. We say that a cell is 1-happy if the cell is empty and all of the cell's orthogonal and diagonal neighbors are occupied (note that a cell may have fewer than 8 neighbors). A cell is 2-happy if the cell is empty and all of the cell's orthogonal neighbors are occupied, but one or more of its diagonal neighbors are empty. A cell is 3-happy if the cell is empty and all of the cell's diagonal neighbors are occupied, but one or more of its orthogonal neighbors are empty. Return a int[] with 3 elements. The first element should be the number of 1-happy cells, the second element should be the number of 2-happy cells, and the third element should be the number of 3-happy cells. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | grid will contain between 1 and 50 elements, inclusive. | ||||||||||||
- | Each element of grid will contain between 1 and 50 characters, inclusive. | ||||||||||||
- | Each element of grid will contain the same number of characters. | ||||||||||||
- | Each character in grid will be either an uppercase 'X' or '.' | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
|