Dsa
Graphs Dfs
Medium
Maze Shortcut Finder
You are given a maze as a 2D grid filled with '0's (path) and '1's (walls). You can teleport from any '0' to any other '0' in a single move. Write a program to determine the minimum number of moves required to reach the exit ('E') from the start ('S'). If unreachable, print -1.
Input Format:
- The first line contains two integers, M (rows) and N (columns).
- The next M lines contain the maze representation.
Output Format:
- Print the minimum number of moves to reach 'E' or -1 if unreachable.
Example:
Input:
3 3
S01
001
1E1
Output:
2
Key concepts
graphsdfsmazes
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