Question bank › Graphs Dfs
Dsa Graphs Dfs Easy

Path Existence in a Grid

You are given a 2D grid of characters where '1' represents land and '0' represents water. Write a program to determine if there exists a path from the top-left corner of the grid to the bottom-right corner, moving only horizontally or vertically through land cells. Input format: - The first line contains two integers r (1 <= r <= 100) and c (1 <= c <= 100), denoting the number of rows and columns. - The next r lines each contain c characters (either '1' or '0'). Output format: - Output 'YES' if a path exists, otherwise output 'NO'. Example: Input: 3 3 1 0 1 1 1 0 0 1 1 Output: YES

Key concepts

graphdfspath finding

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.