Maximum Visibility in a Forest Grid
Problem statement
Each character in forest is open land _ or a tree X. For an open cell, visibility is the number of other open cells visible in the four cardinal directions before a tree or grid boundary blocks the view.
Return [row,column] for the open cell with maximum visibility. Break ties by row-major order. Return [-1,-1] if every cell is a tree.
Function
maximumVisibilityCell(forest: String[]) → int[]Examples
Example 1
forest = ["___X","_X__","__X_"]return = [0,0]The top-left cell sees four other open cells, the maximum.
Constraints
- The rectangular grid has at most
10^6cells.