Java | Set and DFS - Graph
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 {
    private void dfs( int s, Map<Integer,List<Integer>> adjList, boolean[] vis ) {
        vis[s] = true;
        for( int adj : adjList.get(s) )
            if( !vis[adj] )
                dfs( adj, adjList, vis );
    }
    public int numberOfComponents(int[][] properties, int k) {
        int n = properties.length;
        Map<Integer,List<Integer>> adjList = new HashMap<>();
        for( int i=0; i<n; i++ ) {
            Set<Integer> iSet = Arrays.stream( properties[i] )
                                        .boxed()
                                        .collect( Collectors.toSet() );
            for( int j=i+1; j<n; j++ ) {
                Set<Integer> jSet = Arrays.stream( properties[j] )
                                            .boxed()
                                            .collect( Collectors.toSet() );
                jSet.retainAll( iSet );
                if( jSet.size() >= k ) {
                    adjList.putIfAbsent( i, new ArrayList<Integer>() );
                    adjList.putIfAbsent( j, new ArrayList<Integer>() );
                    adjList.get(i).add(j);
                    adjList.get(j).add(i);
                }
            }
        }

        int res = 0;
        boolean[] vis = new boolean[n];
        for( int i=0; i<n; i++ ) {
            if( !vis[i] ) {
                res++;
                if( adjList.containsKey(i) )
                    dfs( i, adjList, vis );
            }
        }
        return res;
    }
}
```
['Java']