Solution: Find the Shortest Path between Two Vertices
Discover how to find the shortest path between two nodes in a directed graph by applying the Breadth-First Search algorithm. Learn to track visited nodes and calculate distances efficiently, enabling you to handle graph traversal problems relevant for coding interviews.
We'll cover the following...
We'll cover the following...
Statement
Given a directed graph of n nodes and two vertices, src and dest, return the length of the shortest path between src and dest. The shortest path will contain the minimum number of edges.
If no path exists between src and dest, return -1.
Constraints:
-
n -
Node.datan Node.datais unique for each node.
Solution
The solution ...