FastPrepMinimum-Step Right-Down Grid Path

Minimum-Step Right-Down Grid Path

Bloomberg LP logoBloomberg LP● EasyNEW GRADONSITE INTERVIEW
Learn

Problem statement

In a binary grid, 1 is passable and 0 is blocked. Starting at the top-left, reach the bottom-right using only one-cell Right or Down moves. Return the minimum number of moves, or -1 if unreachable.

Function

minimumRightDownSteps(grid: int[][]) → int

Examples

Example 1

grid = [[1,0,1],[1,1,1],[0,1,1]]return = 4

A path uses two down and two right moves.

Constraints

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

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int minimumRightDownSteps(int[][] grid) {
  // Write your code here.
}
grid[[1,0,1],[1,1,1],[0,1,1]]
expected4
Checking account…