Using Two Set and Straightforward BFS Traversal
Approach1. Common Elements Calculation:
The commonElement method uses two sets to track the elements of the two arrays. It then counts the number of common elem
# Approach
### 1. Common Elements Calculation:

- The commonElement method uses two sets to track the elements of the two arrays. It then counts the number of common elements between the two sets.

### 2. Graph Construction:

- An adjacency list is created to represent the graph. For each pair of properties, if the number of common elements is greater than or equal to k, an edge is added between the corresponding nodes.

### 3. Connected Components Calculation:

- A straightforward BFS is used to traverse the graph and count the number of connected components. The bfs method marks all nodes reachable from a given node as visited.

This approach ensures that we efficiently count the number of connected components in the graph based on the given conditions.

# Code
```java []
class Solution {
    private int commonElement(int[] arr1, int[] arr2) {
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        for (int x : arr1)
            set1.add(x);
        for (int x : arr2)
            set2.add(x);
        int count = 0;
        for (int x : set2) {
            if (set1.contains(x))
                count++;
        }
        return count;
    }

    private void bfs(boolean[] visited, int node, List<List<Integer>> adj) {
        Queue<Integer> queue = new LinkedList<>();
        queue.offer(node);
        visited[node] = true;
        while (!queue.isEmpty()) {
            int iNode = queue.poll();
            for (int x : adj.get(iNode)) {
                if (!visited[x]) {
                    queue.offer(x);
                    visited[x] = true;
                }
            }
        }
    }

    public int numberOfComponents(int[][] properties, int k) {
        int n = properties.length;
        List<List<Integer>> adj = new ArrayList<>();
        for (int i = 0; i < n; i++)
            adj.add(new ArrayList<>());
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                if (commonElement(properties[i], properties[j]) >= k) {
                    adj.get(i).add(j);
                    adj.get(j).add(i);
                }
            }
        }
        boolean[] visited = new boolean[n];
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (!visited[i]) {
                ans++;
                bfs(visited, i, adj);
            }
        }
        return ans;
    }
}
```
['Breadth-First Search', 'Graph', 'Ordered Set', 'Java']