All practice tasks

Coding (Algo)

Offline Map Distance

Shortest path · Medium

A downloaded tile map marks blocked cells. Navigation needs the fewest orthogonal moves between two cells without contacting a routing service.

Return the shortest walk length or null when no walk exists.

Input

Call

  • Implement solve(input) and return its result. Do not print from solve.

Input object

{ grid:number[][], start:[row,column], end:[row,column] }. grid is rectangular and nonempty; 0 is open and 1 is blocked

What each field means

  • grid — rectangular map; 0 is open and 1 is blocked.
  • start and end — valid [row, column] positions.

Output

Return value and rules

  • Return the fewest moves from start to end, moving up, down, left or right through open cells.
  • Return null if either endpoint is blocked or no route exists.
  • An open start equal to end needs 0 moves.

Constraints

  • 1 <= rows, columns <= 200
  • Only up, down, left and right moves are allowed; indexes are valid. Do not mutate grid.

Examples

Example 1

{
  "end": [
    1,
    1
  ],
  "grid": [
    [
      0,
      0
    ],
    [
      1,
      0
    ]
  ],
  "start": [
    0,
    0
  ]
}

Returns

2

Example 2

{
  "end": [
    0,
    0
  ],
  "grid": [
    [
      0
    ]
  ],
  "start": [
    0,
    0
  ]
}

Returns

0

Required complexity

O(rows × columns) time and space

What this task practices

Offline Map Distance is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.