DSU || HashSet || Java
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 {
    class DSU {
        int[] parent, rank;

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

        int find(int x) {
            if (parent[x] != x) {
                parent[x] = find(parent[x]); 
            }
            return parent[x];
        }

        boolean union(int u, int v) {
            int rootU = find(u);
            int rootV = find(v);
            if (rootU == rootV) return false;

            if (rank[rootU] > rank[rootV]) {
                parent[rootV] = rootU;
            } else if (rank[rootU] < rank[rootV]) {
                parent[rootU] = rootV;
            } else {
                parent[rootV] = rootU;
                rank[rootU]++;
            }
            return true;
        }
    }

    public int numberOfComponents(int[][] properties, int k) {
        int n = properties.length;
        DSU dsu = new DSU(n);

        for (int i = 0; i < n; i++) {
            HashSet<Integer> set1 = new HashSet<>();
            for (int num : properties[i]) {
                set1.add(num);
            }

            for (int j = i + 1; j < n; j++) {
                HashSet<Integer> set2 = new HashSet<>();
                for (int num : properties[j]) {
                    set2.add(num);
                }

                if (intersect(set1, set2) >= k) {
                    dsu.union(i, j);
                }
            }
        }

        Set<Integer> unique = new HashSet<>();
        for (int i = 0; i < n; i++) {
            unique.add(dsu.find(i));
        }

        return unique.size();
    }

    private int intersect(HashSet<Integer> set1, HashSet<Integer> set2) {
        int count = 0;
        for (int num : set1) {
            if (set2.contains(num)) {
                count++;
            }
        }
        return count;
    }

    
}

```
['Java']