Java || DFS || Beats 100%
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 {
    public int numberOfComponents(int[][] properties, int k) {
        int n = properties.length;
        Map<Integer, List<Integer>> mp = new HashMap<>();
        for(int i = 0; i < n; i++) {

            for(int j = 0; j < n; j++) {
                if(i == j) continue;

                int res = intersect(properties[i], properties[j]);
                if(res >= k) {
                    mp.putIfAbsent(i, new ArrayList<>());
                    mp.putIfAbsent(j, new ArrayList<>());

                    mp.get(i).add(j);
                    mp.get(j).add(i);
                }
            }
        }

        boolean[] visited = new boolean[n];
        int count = 0;
       for(int i = 0; i < n; i++) {
            if(!mp.containsKey(i)) {
                count++;
                continue;
            }
            if(visited[i]) continue;
            count++;
            dfs(mp, i, visited);
       }
        return count;
    }

    private int intersect(int[] a, int[] b) {
        Set<Integer> st = new HashSet<>();
        Set<Integer> visited = new HashSet<>();
        for(int i : a) {
            st.add(i);
        }

        int c = 0;
        for(int i : b) {
            if(st.contains(i) && !visited.contains(i)) {
                c++;
                visited.add(i);
            }
        }
        return c;
    }

    private void dfs(Map<Integer, List<Integer>> mp, int node, boolean[] visited) {
        visited[node] = true;
        if(!mp.containsKey(node)) return;
        for(int nbr : mp.get(node)) {
            if(visited[nbr]) continue;
            dfs(mp, nbr, visited);
        }
    }
}
```
['Java']