Dsa
Graphs Bfs
Easy
Graph Path Finder
You are given a directed graph represented by an adjacency list, where each node is an integer from 1 to n, and you need to determine if there is a path from a start node to a destination node.
Input format:
The first line contains two integers n (the number of nodes) and m (the number of edges).
The next m lines each contain two integers, u and v, indicating a directed edge from u to v.
The last line contains two integers, start and destination.
Output format:
Print 'Yes' if there is a path from the start node to the destination node, otherwise print 'No'.
Example:
Input:
5 6
1 2
1 3
2 4
3 4
4 5
3 5
1 5
Output:
Yes
Key concepts
graphsbfspathfinding
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