You are given an undirected graph and two vertices, source and destination. Your task is to determine whether a path exists between them.
Return true if a path exists; otherwise, return false.
Input: V = 6, edges = [[0,1],[0,2],[3,5],[5,4],[4,3]], source = 0, destination = 5
Output: false
Explanation: There is no path between vertices 0 and 5.
Input: V = 3, edges = [[0,1],[1,2]], source = 0, destination = 2
Output: true
Explanation: A path exists from vertex 0 to vertex 2.
Input: V = 1, edges = [], source = 0, destination = 0
Output: true
Explanation: The source and destination are the same vertex.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
6 5 0 1 0 2 3 5 5 4 4 3 0 5
false
5 4 0 1 1 2 2 3 3 4 0 4
true