In this post, we are going to discuss leetcode 1135 — Connecting Cities With Minimum Cost, which is asked in Amazon interviews.
Problem Analysis
There are
n
cities labeled from1
ton
. You are given the integern
and an arrayconnections
whereconnections[i] = [xi, yi, costi]
indicates that the cost of connecting cityxi
and cityyi
(bidirectional connection) iscosti
.Return the minimum cost to connect all the
n
cities such that there is at least one path between each pair of cities. If it is…