Dsa
Matrix
Medium
Matrix Path Checker
You are given a binary matrix (0s and 1s). Write a program to determine if there is a valid path from the top-left corner to the bottom-right corner, moving only down or right through cells with a value of 1.
Input Format:
- The first line contains two integers m and n, the dimensions of the matrix.
- The following m lines consist of n binary integers (0 or 1).
Output Format:
- Print 'YES' if a valid path exists, and 'NO' otherwise.
Example:
Input:
3 3
1 0 1
1 1 1
0 1 1
Output:
YES
Key concepts
matrixpathfindingbacktracking
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