Dsa
Graphs Dfs
Easy
Dungeon Escape
You are trapped in a dungeon represented by a grid of integers where positive integers represent paths and negative integers represent obstacles. You can move in all four directions. The goal is to find the shortest path from the top-left corner (0, 0) to the bottom-right corner (m-1, n-1) ignoring obstacles. If it's not possible to reach the goal, print -1.
Input format:
- The first line contains two integers, m and n, the dimensions of the grid.
- The following m lines each contain n integers (either positive or negative).
Output format:
- Print the minimum number of steps required to reach the bottom-right corner, or -1 if it's not reachable.
Example:
Input:
3 3
0 1 0
1 0 2
0 3 0
Output:
4
Key concepts
graphsdfspathfinding
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