Problem · Graph

Minimum Grid Moves

Learn this problem
MediumAtlassian logoAtlassianINTERNFULLTIMEOA

Problem statement

In a zero-and-one maze, move from the top-left cell to the bottom-right. A move travels between 1 and k cells horizontally or vertically, but it cannot cross or land on an obstacle. Return the minimum number of moves, or -1 if the destination is unreachable.

Function

getMinimumMoves(maze: int[][], k: int) → int

Examples

Example 1

maze = [[0,0],[1,0]]k = 2return = 2

Move right once and down once; the obstacle blocks the other route.

Constraints

  • 1 <= rows, columns, k <= 100
  • Cells contain only 0 or 1.

More Atlassian problems

drafts saved locally
public int getMinimumMoves(int[][] maze, int k) {
  // Write your code here.
}
maze[[0,0],[1,0]]
k2
expected2
checking account