Visit Every Node Shortest Problem
Visit Every Node Shortest Problem — ExecCode Hard DSA Practice
Solve the Visit Every Node Shortest problem on ExecCode. Free online hard DSA practice in Graph. Write and run code in Java, C++, Python — no signup required to run.
Problem description
An undirected connected graph is given as adjacency lists. You may start at any node and walk edges (nodes can be revisited). Find the shortest walk that visits every node at least once. Return the length of the shortest such walk (number of edges). You are given: graph — adjacency list of an undirected graph Return integer edge count. Revisits are allowed; you do not need a Hamiltonian path if a shorter covering walk exists with revisits.
Examples
Input {'graph': [[1, 2, 3], [0], [0], [0]]}; Output 4. Input {'graph': [[1], [0, 2, 4], [1, 3, 4], [2], [1, 2]]}; Output 4. Input {'graph': [[1], [0]]}; Output 1
Constraints
Graph is connected
Practice Visit Every Node Shortest free on ExecCode. Browse DSA problems, topic map, and placement guides.