Best and easy solution to get an idea how to approach such Questions
IntuitionComplexity
Time complexity: O(n² * m)


Space complexity:
Adjacency list: O(n²)
Visited array: O(n)
HashSets: O(m)
Recursion stack: O(n)
Overall Space
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
    just follow the question , use hashSet to find distinct common elements in the array , and after that connect those nodes to each other by adding them to the adj list , and its done.

    The graph is completed , now apply simple bfs and dfs too find the number of connected components. 

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

- Space complexity:

    Adjacency list: O(n²) 
    Visited array: O(n)
    HashSets: O(m)
    Recursion stack: O(n)
    Overall Space Complexity:

   - O(n² + m) (since O(n²) dominates).
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int getCnt(int i , int j , int[][] properties ,int m ){
        Set<Integer> a = new HashSet<>();
        Set<Integer> b = new HashSet<>();
        for(int k = 0 ; k < m ; k++){
            a.add(properties[i][k]);
            b.add(properties[j][k]);
        }
        int cnt = 0;
        for(int p : a){
            if(b.contains(p)) cnt++;
        }

        return cnt;
    }
    public void dfs(int node ,List<Integer>[] adj, boolean[] vis ){
        vis[node]=true;
        for(int i: adj[node]){
            if(!vis[i]){
                dfs(i,adj,vis);
            }
        }
    }
    public int numberOfComponents(int[][] properties, int k) {
        int n = properties.length;
        int m = properties[0].length;
        List<Integer>[] adj = new ArrayList[properties.length];
        for(int i = 0 ; i < n ; i++){
            adj[i] = new ArrayList<>();
        }
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                if(i==j) continue;
                int cnt = getCnt(i,j,properties,m);
                if(cnt>=k){
                    adj[i].add(j);
                    adj[j].add(i);
                }
            }
        }

        boolean vis[] = new boolean[n];
        int cnt = 0;
        for(int i = 0 ; i < n ; i++){
            if(!vis[i]){
                dfs(i,adj,vis);
                cnt++;
            }
        }

        return cnt;
    }
}
```
['Array', 'Hash Table', 'Depth-First Search', 'Java']