InterviewDB Question

Efficient Cost: Minimize Total Cost to Connect All Nodes in a Network

Question Details

Problem You are given n nodes and a list of potential edges, each with a cost. Find the minimum total cost to connect all nodes (i.e., build a minimum spanning tree). If it is impossible to connect all nodes, return -1. Example: Approach Kruskal's with Union-Find: sort edges by cost, greedily add edges that don't form a cycle. Time: O(E log E). Follow-ups When would you prefer Prim's algorithm over Kruskal's? What if some nodes already have a free connection (cost = 0) — does the algorithm chang…

Full Details

🔒

Unlock all Snowflake questions

Full insider details, leaked discussions, and candidate experiences.

or every company, $100/year →

About This Question

This is a reported interview question from a snowflake interview during the oa round.

It covers the following topics: System Design, Coding, Union Find, Oa .