Java || Find and Union || Graph Question
\nclass Solution {\n    int find(int x, int[] parent){\n            if(parent[x] == -1) return x;\n        \n        parent[x] = find(parent[x], parent);\n     
```\nclass Solution {\n    int find(int x, int[] parent){\n            if(parent[x] == -1) return x;\n        \n        parent[x] = find(parent[x], parent);\n        return parent[x];\n        }\n    \n    void union(int x, int y, int[] parent){\n        int xp = find(x,parent);\n        int yp = find(y,parent);\n        if(xp!= yp) parent[yp] = xp;\n    }\n    public int largestComponentSize(int[] A) {\n        int n = A.length;\n        int[] parent = new int[100001];\n        for(int i=0;i<100001;i++) parent[i] = -1;\n        \n        for(int i=0;i<n;i++){\n            for(int k=2;k<=Math.sqrt(A[i]);k++){\n                if(A[i]%k == 0){\n                    union(A[i],k,parent);\n                    union(A[i],A[i]/k,parent);\n                }\n            }\n        }\n        int count=0;\n        HashMap<Integer, Integer> hm = new HashMap<>();\n        for(int i=0;i<n;i++){\n            int p = find(A[i],parent);\n            count = Math.max(count, 1+hm.getOrDefault(p,0));\n            hm.put(p,1+hm.getOrDefault(p,0));\n        }\n        return count;\n    }\n}\n```
[]