Directional Distance to Mines and Boundaries
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^6cells.