Dsa
Graphs Dfs
Easy
Garden Path Finder
You are tasked with navigating a garden represented as a grid. Each cell in the grid can either be a flower (1) or empty (0). You need to find a path from the top-left corner of the grid to the bottom-right corner only moving up, down, left, or right through empty cells. Write a program that returns 'YES' if such a path exists, or 'NO' otherwise.
Input Format:
- The first line contains two integers N and M, the dimensions of the grid.
- The next N lines each contain M integers (0s or 1s) representing the grid.
Output Format:
- Print 'YES' if a path exists, otherwise print 'NO'.
Example:
Input:
3 3
0 1 0
0 0 0
1 1 0
Output:
YES
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