 All Problems
Find if Path Exists in Graph
easy
union-find
graph
bfs
dfs
amazon
google

There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1. Given edges and two integers source and destination, return true if there is a valid path from source to destination, otherwise false.

Example 1:

Input: n=3, edges=[[0,1],[1,2],[2,0]], source=0, destination=2
Output: true

Example 2:

Input: n=6, edges=[[0,1],[0,2],[3,5],[5,4],[4,3]], source=0, destination=5
Output: false

Constraints:

  • 1 <= n <= 2 * 10^5
  • 0 <= edges.length <= 2 * 10^5
Run to check your code against the sample cases, or submit to run every case