Dsa
Backtracking
Easy
Pathfinding through Grid
You are given a 2D grid of size n x m containing '0's and '1's, where '0' represents an empty cell and '1' represents an obstacle. Your task is to find all unique paths from the top-left corner (0, 0) to the bottom-right corner (n-1, m-1) where you can only move down or right. Print the paths as a list of coordinates (x, y). If no path exists, print 'No Path'. The input consists of multiple lines: the first line contains two integers n and m, followed by n lines each containing m integers (0 or 1). Example:
Input:
3 3
0 0 0
1 0 0
0 0 0
Output:
[(0, 0), (0, 1), (1, 1), (2, 1), (2, 2)]
[(0, 0), (0, 1), (1, 1), (1, 2), (2, 2)]
Key concepts
backtrackinggridpath
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