Algorithm · Amazon · Medium
A data center holds n machines labeled 0 through n - 1. The array connections lists the cables that are already installed, and each entry joins two machines in both directions. A single operation lets you unplug any installed cable and plug it back in between any two machines you choose. Find the fewest operations required so that every machine can reach every other machine through the network. If no sequence of operations can achieve this, the answer is -1. Input Format The…