Code Room
CodingMedium
Question
You must connect n cities (0..n-1) with cables. You are given a list of candidate cables as [u, v, cost]. Return the minimum total cost to connect all cities so that every city is reachable from every other. If it is impossible to connect them all, return -1. The graph is undirected; duplicate cables and self-cables (u == v) may appear.
Implement
min_cable_cost(n: int, cables: list[list[int]]) → intExamples
in
[4,[[0,1,1],[1,2,2],[2,3,3],[0,3,10]]]out6What 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.
Learn the concepts
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.