backbenchcode
← all problemsnext: Counting Distinct Paths
#06MediumData Structures · 47% acceptance

Lab Network Reachability

GraphBFSDFS

Given a directed graph as an adjacency list and two nodes `src` and `dst`, return whether there is a path from `src` to `dst`.

Reagent dependency chains, citation graphs, pathway maps — all of these are graphs. Traversal is how you query them.

Examples

Input: graph = {0:[1,2], 1:[3], 2:[3], 3:[]}, src=0, dst=3

Output: true

Input: same graph, src=3, dst=0

Output: false

Constraints

Hints

solution.pyPython 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Test console

// hit Run to execute the sample tests

// Interactive editor preview. Live code execution arrives with your early-access cohort.