The Question
CodingOptimize Water Distribution System
There are n houses in a neighborhood. You want to provide water to every house at the minimum possible cost. For each house i, you have two options:
1. Build a well directly at the house with cost wells[i-1].
2. Lay a pipe connecting house i to another house j with a specific cost given in an array pipes, where pipes[k] = [house1, house2, cost].
Connections are bidirectional. Multiple pipes can exist between the same pair of houses. Find the minimum total cost to ensure every house has access to water (either via its own well or via a connection to a house that has access to water).
Java
Kruskal's Algorithm
Union-Find
MST
Greedy