Contest - 442 || Question-2
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 DSU{
    List<Integer> parent = new ArrayList<>();
    List<Integer> size = new ArrayList<>();// For Path Compression

    public DSU(int n){
        for(int i=0;i<n;i++){
            parent.add(i);
            size.add(1);
        }
    }

    public int find_Parent(int x){

        if(parent.get(x)==x) return x;

        int x_parent = find_Parent(parent.get(x));
        parent.set(x,x_parent);

        return parent.get(x);

    }

    public void take_union(int x , int y){

        int x_parent = find_Parent(x);
        int y_parent = find_Parent(y);

        if(x_parent==y_parent) return;

        if(size.get(x_parent)>size.get(y_parent)){
            parent.set(y_parent ,x_parent );
            size.set(x_parent , size.get(x_parent)+size.get(y_parent));
        }
        else{
            parent.set(x_parent ,y_parent );
            size.set(y_parent , size.get(x_parent)+size.get(y_parent));
        }


    }

    public List<Integer> getParentList() {
        return parent;
    }
    
    public List<Integer> getSizeList() {
        return size;
    }

}
class Solution {
    public int numberOfComponents(int[][] nums, int k) {
        
        int n =  nums.length;
        boolean[][] present = new boolean[n][101];
        for (int i = 0; i < n; i++) {
          for (int num : nums[i]) {
             present[i][num] = true;
          }
        }
        
        DSU ds = new DSU(n);
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(i==j) continue;
                int size = 0;
                for (int x = 1; x <= 100; x++) {
                    if (present[i][x] && present[j][x]) {
                        size++;
                    }
                }
                if (size >= k) {
                    ds.take_union(i, j);
                }
            }
        }
        
        List<Integer> list = ds.getParentList();
        // System.out.println(list);
        HashSet<Integer> set = new HashSet<>();
        for(int i:list) set.add(i);
        
        return set.size();
        
    }
}
```
['Union Find', 'Java']