Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Maze Path From A to B

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

Your question is Maze Path From A to B. 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

Delta Air Lines models an airport concourse as a rectangular grid. Open cells represent walkable areas, while blocked cells represent restricted zones. Given a start point and destination, return the shortest valid path between them using only four-directional movement.

Formal Specification

Implement shortest_path(maze, start, end), where maze is a list of equal-length lists containing 0 for an open cell and 1 for a blocked cell. start and end are coordinate lists of the form [row, column]. Return a list of coordinate lists beginning with start and ending with end. If no path exists, return [].

The path may move up, down, left, or right, but not diagonally. The start and end cells are guaranteed to be within the grid and open. If start == end, return a path containing that single coordinate.

Constraints

  • 1 <= rows, columns <= 200
  • maze is rectangular
  • Each maze cell is either 0 or 1
  • start and end are valid coordinates for open cells
  • Movement is allowed only up, down, left, or right
  • Any shortest path is acceptable when multiple paths exist

Function Signature

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