FastPrepDirectional Distance to Mines and Boundaries

Directional Distance to Mines and Boundaries

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

In mines, 1 is a mine and 0 is open. For every open cell, count open cells reachable in each cardinal direction before the first mine or boundary, and output the sum. Output 0 for mine cells.

Function

directionalDistances(mines: int[][]) → int[][]

Examples

Example 1

mines = [[0,0,1],[0,0,0]]return = [[2,2,0],[3,3,2]]

Each value sums unobstructed open cells in the four directions.

Constraints

  • The rectangular grid has at most 10^6 cells.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[][] directionalDistances(int[][] mines) {
  // Write your code here.
}
mines[[0,0,1],[0,0,0]]
expected[[2,2,0],[3,3,2]]
Checking account…