The Deep Dive (DFS)
MediumAcc. 90.2%
+35 XP 15
The Deep Explorer (DFS)
Depth-First Search (DFS) is like a brave explorer following a single path until they hit a dead end, then backtracking to find the next available trail. It is essential for discovering paths, cycles, and connectivity in complex networks.
The Assignment
Your mission is to explore the deepest reaches of the network. Your function receives an adjacencyList and a startNode.
- Use a Recursion or a Stack to travel as deep as possible.
- Maintain a Visited Set to track where you have already been.
- For the current node:
- Print its identifier.
- Mark it as visited.
- Recursively visit every unvisited neighbor.
01EXAMPLE 1
Input
adjList=[[1, 2], [0], [0]]Output
0
1
2Explanation: Path: 0 -> 1 -> 2.
Constraints
- Standard recursive DFS.
GraphsAlgorithms
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
adjList[[1,2],[0,2],[0,1]]
Expected Output
0 1 2
Click RUN to test your solution