Java Disjoint Set Union
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int f(int[] a,int[] b){
        HashSet<Integer> set=new HashSet<>();
        for(int i:a){
            set.add(i);
        }

        int cnt=0;
        for(int i:b){
            if(set.contains(i)){
                cnt++;
                set.remove(i);
            }
        }
        return cnt;
    }

    public int getPar(int x,int[] parent){
        if(parent[x]==x)return x;
        parent[x]=getPar(parent[x],parent);
        return parent[x];
    }

    public void union(int u,int v,int[] parent){
        int ultpu=getPar(u,parent);
        int ultpv=getPar(v,parent);

        if(ultpu==ultpv){
            return;
        }else{
            parent[ultpv]=ultpu;
        }
        
    }
    
    public int numberOfComponents(int[][] properties, int k) {
        int n=properties.length;

        int[] parent=new int[n];
        for(int i=0;i<n;i++){
            parent[i]=i;
        }

        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(f(properties[i],properties[j])>=k){
                    union(i,j,parent);
                }
            }
        }
        int res=0;
        for(int i=0;i<n;i++){
            if(parent[i]==i){
                res++;
            }
        }
        return res;
    }
}
```
['Union Find', 'Java']