Search⌘ K
AI Features

Solution: Find the Shortest Path between Two Vertices

Explore how to find the shortest path between two vertices in a directed graph using the Breadth-First Search algorithm. Learn to implement BFS with a queue to track visited nodes and distances, ensuring efficient traversal. Understand time and space complexities related to this graph problem to prepare effectively for coding interviews.

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:

  • 00 \leq n 100\leq 100
  • 00 \leq Node.data
...