FastPrepMaximum Visibility in a Forest Grid

Maximum Visibility in a Forest Grid

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

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^6 cells.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[] maximumVisibilityCell(String[] forest) {
  // Write your code here.
}
forest["___X","_X__","__X_"]
expected[0,0]
Checking account…