Beats 97%; Simple Counting and Storing Indices First and then DFS
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, largest = 0;
        int[][] commons = new int[n][n];
        for (int[] elements : properties) {
            for (int element : elements) {
                largest = Math.max(element, largest);
            }
        }
        List<List<Integer>> indices = new ArrayList<>();
        for (int i = 0; i <= largest; i++) {
            indices.add(new ArrayList<>());
        }
        for (int i = 0; i < properties.length; i++) {
            Set<Integer> unique = new HashSet<>();
            for (int j = 0; j < properties[i].length; j++) {
                if (!unique.contains(properties[i][j])) {
                    for (int element : indices.get(properties[i][j])) {
                        commons[i][element]++;
                        commons[element][i]++;
                    }
                    indices.get(properties[i][j]).add(i);
                    unique.add(properties[i][j]);
                }
            }
        }
        List<List<Integer>> adj = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            adj.add(new ArrayList<>());
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (commons[i][j] >= k) {
                    adj.get(i).add(j);
                }
            }
        }
        boolean vis[] = new boolean[n];
        int components = 0;
        for (int i = 0; i < n; i++) {
            if (!vis[i]) {
                dfs(i, adj, vis);
                components++;
            }
        }
        return components;
    }

    public void dfs(int node, List<List<Integer>> adj, boolean[] vis) {
        vis[node] = true;
        for (int child : adj.get(node)) {
            if (!vis[child]) {
                dfs(child, adj, vis);
            }
        }
    }
}
```
['Java']