SIMPLE DFS APPROACH USING PYTHON
Complexity

Time complexity:
O(n2)


Space complexity:
O(n)

Code
# Complexity
- Time complexity:
O(n2)

- Space complexity:
O(n)

# Code
```python3 []
from collections import defaultdict


class Solution:
    def numberOfComponents(self, properties: List[List[int]], k: int) -> int:
        n = len(properties)
        res = 1
        visit = set()
        visit.add(0)
        graph = defaultdict(list)

        def intersect(a, b):
            return len(set(a) & set(b))

        for i in range(n):
            for j in range(n):
                if intersect(properties[i], properties[j]) >= k and i != j:
                    graph[i].append(j)
                    graph[j].append(i)

        def dfs(index):
            for neighbour in graph[index]:
                if neighbour in visit:
                    continue
                visit.add(neighbour)
                dfs(neighbour)

        dfs(0)
        for i in range(n):
            if i not in visit:
                dfs(i)
                res += 1
        return res

```
['Python3']