Simple Brute force | DSU
Code
# Code
```cpp []
class Solution {
public:
    struct DSU{
        vector<int> par, chi;
        int components = 0;
        DSU(int n){
            components = n;
            for(int i=0; i < n; i++){
                par.push_back(i);
                chi.push_back(1);
            }
        }
        int getP(int n){
            return par[n] = (par[n] == n ? n : getP(par[n]));
        }
        void join(int a, int b){
            a = getP(a);
            b = getP(b);
            if(chi[a] >= chi[b]){
                par[b] = a;
                chi[a] += chi[b];
            }
            else{
                par[a] = b;
                chi[b] += chi[a];
            }
            components--;
        }
        int countComponents(){
            return components;
        }
    };
    int numberOfComponents(vector<vector<int>>& properties, int k) {
        int n = properties.size();

        auto intersect = [](auto &a, auto &b)->int{   
            unordered_set<int> st(a.begin(), a.end());
            int common=0;
            for(int x : b){
                if(st.count(x)){
                    common++;
                    st.erase(x);
                }
            }
            return common;
        };

        DSU dsu(n);
        sort(properties.begin(), properties.end(), [](auto& a, auto& b) {
            return a.size() < b.size();
        });
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n && properties[j].size() <= properties[i].size() + k; j++){
                if(intersect(properties[i], properties[j]) >= k){
                    int par_u = dsu.getP(i);
                    int par_v = dsu.getP(j);
                    if(par_u != par_v){
                        dsu.join(i,j);
                    }
                }
            }
        }

        return dsu.countComponents();
    } 
};



```
['Union Find', 'C++']