Build an Undirected Graph and Traverse with DFS

Asked at Google DeepMind · Coding Questions · Difficulty: Easy · Last asked Jun 18, 2026

You are given the edges of an undirected graph as a list of node pairs. Build the graph and return the order in which a depth-first search (DFS) from a given start node first visits each node. To make the answer unique, the search always goes to the smallest unvisited neighbour first.

Loading the problem…