Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Shortest Path in Grid Lot

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Shortest Path in Grid Lot. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given an m x n grid of integers, find the length of the shortest path from a start cell to a destination cell. Each cell is either open (0) or blocked (1). You may move one step at a time in four directions: up, down, left, or right. Return the minimum number of steps needed to reach the destination, or -1 if no path exists.

Constraints

  • 1 <= m, n <= 200
  • grid[i][j] is either 0 or 1
  • start.length == 2 and end.length == 2
  • 0 <= start[0], end[0] < m
  • 0 <= start[1], end[1] < n

Function Signature

def shortest_path_grid(grid, start, end):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output