Challenge: Check If a Path Exists between Two Vertices

Try to solve the Check If a Path Exists between Two Vertices problem.

We'll cover the following

Statement

Given a 2D list, edges, representing a bidirectional graph, where each vertex is labeled from 00 to n1n-1. Each edge in the graph is represented as a pair, [xi,yi][x_i, y_i], showing a bidirectional edge between xix_i and yiy_i. Each pair of vertices is connected by at most one edge, and no vertex is connected to itself.

Determine whether a valid path exists from the source vertex to the destination vertex. If it exists, return TRUE, otherwise return FALSE.

Constraints:

  • 11\leq n 102\leq 10^2

  • 00 \leq edges.length n(n1)/2\leq n(n-1)/2

  • edges[i].length =2 = 2

  • 0xi,yin10 \leq x_i,y_i \leq n-1

  • xiyi x_i\ne y_i

  • 00\leq source, destination n1\leq n - 1

  • There are no duplicate edges

  • There are no self-edges

Examples

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