Code RoomShortest Hamiltonian path
HardPrep Room Coding #1046

Shortest Hamiltonian path

CodingAlgorithms & data structuresSenior–Staff~35 min

Given a symmetric distance matrix `dist` for N nodes (dist[i][j] is the edge length), find the length of the shortest Hamiltonian path that visits every node exactly once. The path may start and end at any node (it is an open path, not a cycle). N is small (up to ~13). Return the minimum total length.

Implement
shortest_hamiltonian_path(dist: list[list[int]]) → int
Examples
in[[[0,10,15,20],[10,0,35,25],[15,35,0,30],[20,25,30,0]]]out50
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 35 min
InputExpectedGot
[[[0,10,15,20],[10,0,35,25],[15,35,0,30],[20,25,30,0]]]50not run yetsample