✔ JAVA | Solution using Disjoint Set Union + HashMap
\nclass DSU {\n    ArrayList<Integer> parent = new ArrayList();\n    public DSU (int n) {\n        for (int i = 0; i < n; i++)\n            parent.add(i);\n    
```\nclass DSU {\n    ArrayList<Integer> parent = new ArrayList();\n    public DSU (int n) {\n        for (int i = 0; i < n; i++)\n            parent.add(i);\n    }\n    int findParent(int n) {\n        if(parent.get(n) == n)\n            return n;\n        parent.set(n, findParent(parent.get(n)));\n        return parent.get(n);\n    }\n    void union(int u, int v) {\n        int uParent = findParent(u);\n        int vParent = findParent(v);\n        \n        if(uParent != vParent)\n            parent.set(uParent, parent.get(vParent));\n    }\n}\nclass Solution {\n    public int largestComponentSize(int[] nums) {\n        int n = nums.length;\n        int x = nums[0];\n        for (int num : nums)\n            x = Math.max(x, num);\n        DSU dsu = new DSU(x + 1);\n        \n        for (int num : nums) {\n            for (int i = 2; i * i <= num; i++) {\n                if (num % i == 0) {\n                    dsu.union(num, i);\n                    dsu.union(num, num/i);\n                }\n            }\n        }\n        Map<Integer, Integer> map = new HashMap();\n        int ans = 1;\n        for (int num : nums) {\n            int par = dsu.findParent(num);\n            map.put(par, map.getOrDefault(par, 0) + 1);\n            ans = Math.max(ans, map.get(par));\n        }\n        return ans;\n    }\n}\n```\nPlease **upvote** :-)
['Union Find', 'Java']