C++ Solution simple approach using graph construction and dfs
ApproachFor the given constraints, following approach works fine.
Construct a graph using the given approach and then find number of connected componentsComplex
# Approach
For the given constraints, following approach works fine.
Construct a graph using the given approach and then find number of connected components

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

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

# Code
```cpp []
class Solution {
public:
    int numberOfComponents(vector<vector<int>>& properties, int k) {
        int n = properties.size();

        vector<vector<int>> graph = constructGraph(properties, k);
        vector<int> visited(n, 0);

        int connectedComponents = 0;

        for (int i = 0; i < n; ++i) {
            if (!visited[i]) {
                dfs(graph, i, visited);
                connectedComponents++;
            }
        }

        return connectedComponents;
    }

private:
    void dfs(vector<vector<int>>& graph, int node, vector<int>& visited) {
        visited[node] = 1;

        for (auto u : graph[node]) {
            if (!visited[u]) {
                dfs(graph, u, visited);
            }
        }
    }

    vector<vector<int>> constructGraph(vector<vector<int>>& properties, int k) {
        int n = properties.size();
        int m = properties[0].size();

        vector<vector<int>> graph(n, vector<int>());

        for (int i = 0; i < n; ++i) {
            set<int> s1;
            for (int l = 0; l < m; ++l) {
                s1.insert(properties[i][l]);
            }
            for (int j = i + 1; j < n; ++j) {
                set<int> s2;
                for (int l = 0; l < m; ++l) {
                    if (s1.find(properties[j][l]) != s1.end()) {
                        s2.insert(properties[j][l]);
                    }
                }
                if (s2.size() >= k) {
                    graph[i].push_back(j);
                    graph[j].push_back(i);
                }
            }
        }

        return graph;
    }
};
```
['Array', 'Greedy', 'Depth-First Search', 'Graph', 'Ordered Set', 'Strongly Connected Component', 'C++']