Company: HiLabs_SDE
Difficulty: medium
Connected components Problem Description You're given an undirected graph made up of N nodes, each labeled with a number, supplied as an array `a` of N distinct integers where `a[i]` is the label written on the `i`th node. Two nodes `i` and `j` are joined by an edge exactly when `lcm(a[i], a[j]) Here, the LCM of two numbers is the smallest positive integer divisible by both. Report how many connected components this graph has. Notes: 1-based indexing is followed. A connected component of an undirected graph is an induced subgraph in which any two vertices are connected to each other by paths, and which is connected to no additional vertices in the rest of the graph. Function Description Complete the function solve . This function takes the following 2 parameters and returns the required answer: N : Represents the size of array arr arr : Represents the elements of array arr Input Format Note: Use this input format if you are testing against custom input writing code in a language where