Code Room
CodingHardcod-g477
Subject Bitmask dpLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.