Problem
Minimum Spanning Tree Weight in a Complete Binary Graph
Learn this problemProblem statement
You are given n nodes in a complete undirected graph. Some edges have weight 1; every other edge has weight 0. The weight-1 edges are given in the array oneEdges, where each edge is represented as [u, v].
Return the total weight of a minimum spanning tree of this complete graph.
Function
minimumSpanningTreeWeight(n: int, oneEdges: int[][]) → intExamples
Example 1
n = 4oneEdges = [[1, 2], [2, 3], [3, 4]]return = 0All edges not listed in oneEdges have weight 0. The zero-weight edges can connect all four nodes, so the MST weight is 0.
Example 2
n = 3oneEdges = [[1, 2], [1, 3], [2, 3]]return = 2Every edge has weight 1, so any spanning tree uses two weight-1 edges.
Constraints
1 <= n <= 2 * 10^50 <= oneEdges.length <= min(n * (n - 1) / 2, 2 * 10^5)1 <= u < v <= nfor each edge inoneEdgesoneEdgescontains no duplicate edges.
More Uber problems
- Minimum Refueling StopsONSITE INTERVIEW · Seen Jul 2026
- Last Truck to Leave the LaneOA · Seen Jul 2026
- Chain of CommandOA · Seen Jul 2026
- Jump Game with Prime-3 StepsOA · Seen Jun 2026
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026