Back to the 100
Problem 025Graphs
Easy

Find if Path Exists in Graph

025

Given n, undirected edges, source, and destination, return true if a path exists.

EXAMPLES

Example 1
Input
{
  "n": 3,
  "edges": [
    [
      0,
      1
    ],
    [
      1,
      2
    ],
    [
      2,
      0
    ]
  ],
  "source": 0,
  "destination": 2
}

Output
true

FUNCTION SHAPE

n: intedges: intMatrixsource: intdestination: intbool
00:00
2 local tests readyRun with ⌘/Ctrl + Enter. Your code stays in this browser.

Runs solve(...) locally in a browser worker. SWE Playbook does not submit your code. Only run code you trust; Python code may access the network.