Given a graph represented as an adjacency list, implement a function to perform a depth-first search and return the order in which the nodes are visited. The graph is represented as a list of lists, where each inner list contains the neighbors of a node.
Explanation: The depth-first traversal order of the graph is 0, 1, 2, 3 because we visit node 0 first, then its neighbors 1 and 2, and then their neighbors.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak