Question bank › Backtracking
Dsa Backtracking Hard

Maze of Passages

You are in a maze represented by a 2D grid, where 0 represents an open passage and 1 represents a wall. Starting from the top-left corner (0,0), you need to find all unique paths to the bottom-right corner (n-1,m-1) of the maze. A path can be formed by moving up, down, left, or right. Print all valid paths as lists of coordinates from start to end. Input: - First line contains two integers n and m (1 ≤ n, m ≤ 10), the dimensions of the maze. - Next n lines each contain m integers (0 or 1) representing the maze grid. Output: - Print each unique path as a list of coordinates (x, y) from the start to the end, one path per line. Example: Input: 3 3 0 0 1 0 0 0 1 0 0 Output: [(0, 0), (0, 1), (1, 1), (2, 1), (2, 2)] [(0, 0), (1, 0), (1, 1), (2, 1), (2, 2)]

Key concepts

backtrackinggridpathfinding

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.