dsa · easy

Find if Path Exists in Graph

GreyOrangeGraphQueueFoundation

Undirected graph, n nodes 0..n-1, edge list edges. Return whether a path exists from source to destination.

Arguments

**Example:** n=3, edges=[[0,1],[1,2]], source=0, destination=2true.

Constraints

1 <= n <= 200 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
3
[[0,1],[1,2]]
0
2

Expected:
true

Example 2

Input:
6
[[0,1],[0,2],[3,5],[5,4],[4,3]]
0
5

Expected:
false

Open in the Dojo editor