Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find All Maze Paths

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

Your question is Find All Maze Paths. 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

A Verily Study Watch analysis workflow represents a coverage area as a rectangular grid. Given a maze, a start cell A, and a destination cell B, return every simple path from A to B.

You may move one cell up, down, left, or right. You cannot move through blocked cells or visit the same cell more than once in a path. Return paths in the order discovered by trying directions right, down, left, up. Each path must include both endpoints.

Formal Specification

Implement find_all_paths(maze, start, end).

  • maze is a rectangular list[list[int]], where 0 is open and 1 is blocked.
  • start and end are coordinates represented as two-element lists [row, column].
  • Return a list of paths, where each path is a list of coordinate lists.
  • Return [] when no path exists.
  • The start and destination cells are guaranteed to be open and within bounds.

Constraints

  • 1 <= rows, columns <= 8
  • maze is rectangular
  • Each maze cell is either 0 or 1
  • start and end are valid open cells
  • Movement is limited to up, down, left, and right
  • A path cannot repeat a cell

Function Signature

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