Practice Shortest Path Visiting All Nodes
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Shortest Path Visiting All Nodes
Problem Statement
You have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an edge. Return the length of the shortest path that visits every node. You may start and stop at any node, you may revisit nodes multiple times, and you may reuse edges.
Source: Shortest Path Visiting All Nodes on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
graph = [[1,2,3],[0],[0],[0]]
4
# Example 2
graph = [[1],[0,2,4],[1,3,4],[2],[1,2]]
4
Constraints
Related LeetCode Problems
Practice more problems similar to Shortest Path Visiting All Nodes.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.