Challenge: Find the Shortest Path Between Two Vertices

Given a graph, find the shortest path between two vertices. A solution is placed in the "solution" section to help you, but we would suggest trying to solve it on your own first.

Problem Statement

In this problem, you have to implement the findMin() method to take an undirected graph and two vertices (A and B) as inputs, and return the length of the shortest path between those vertices in Graph. Remember, the shortest path will contain the minimum number of edges. An illustration is provided below for your understanding:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.