Tap here to switch tabs
Problem
Submissions

Problem: Shortest Path Visiting All Nodes

hard
40 min
Understand how to find the shortest path that visits every node in an undirected connected graph. Explore using adjacency lists and graph algorithms, including revisiting nodes and reusing edges, to solve this problem efficiently.

Statement

You are given an undirected connected graph with n nodes numbered from 00 to n1n-1. The graph is provided as an adjacency list, graph, where graph[i] contains all nodes that share an edge with node i.

Your task is to find the length of the shortest path that visits every node. You may:

  • Start from any node.

  • End at any node.

  • Revisit nodes and reuse edges as many times as needed.

Constraints:

  • n ==== graph.length

  • 11 \leq n 12\leq 12

  • 00 \leq graph[i].length << n

  • graph[i] does not contain i.

  • If graph[a] contains b, then graph[b] contains a.

  • The input graph is always connected.

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths
Tap here to switch tabs
Problem
Submissions

Problem: Shortest Path Visiting All Nodes

hard
40 min
Understand how to find the shortest path that visits every node in an undirected connected graph. Explore using adjacency lists and graph algorithms, including revisiting nodes and reusing edges, to solve this problem efficiently.

Statement

You are given an undirected connected graph with n nodes numbered from 00 to n1n-1. The graph is provided as an adjacency list, graph, where graph[i] contains all nodes that share an edge with node i.

Your task is to find the length of the shortest path that visits every node. You may:

  • Start from any node.

  • End at any node.

  • Revisit nodes and reuse edges as many times as needed.

Constraints:

  • n ==== graph.length

  • 11 \leq n 12\leq 12

  • 00 \leq graph[i].length << n

  • graph[i] does not contain i.

  • If graph[a] contains b, then graph[b] contains a.

  • The input graph is always connected.

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths