Company: Agoda_26july
Difficulty: medium
Minimum Operations to Connect All Computers Problem Description A set of computers may be connected by ethernet cables, with each cable connecting exactly two distinct computers. Computers are considered connected if they have either a direct or indirect connection to each other. Initially, some groups of computers are connected to each other, but others may be disconnected. You can perform one type of operation: remove a cable between any two computers and use it to connect any other pair of computers. Determine the minimum number of such operations required to connect all computers. If it is not possible to connect all computers, return -1. Examples Example 1: Input: comp_nodes = 4, comp_edges = 3, comp_from = [1,1,3], comp_to = [2,3,2] Output: 1 Explanation: Initially, there are connections between computers (1,2), (1,3), and (2,3), but computer 4 is disconnected. By removing the cable between computers 2 and 3 and placing it between computers 2 and 4, all computers become connected