Dsa
Graphs Dfs
Easy
Path Existence
Determine whether there exists a path between two nodes in an undirected graph. The graph will be described by an integer N (the number of nodes) followed by M pairs of integers representing edges. The last line of input will consist of two integers representing the starting and ending nodes. For example:
4
0 1
1 2
2 3
0 3
This indicates there are 4 nodes, edges between 0-1, 1-2, and 2-3, and we want to find a path from node 0 to node 3. Output 'YES' if a path exists, otherwise 'NO'.
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