---
# System prepended metadata

title: 'Walkthrough: Friend Circles'

---

# Walkthrough: Friend Circles
[Original Problem](https://leetcode.com/problems/friend-circles/)

**Python**
```python
def find_friend_circles(M):
    visited = [0 for _ in range(len(M))]
    count = 0
    for i in range(len(M)):
        if not visited[i]:
            dfs(M, visited, i)
            count += 1
    return count
    
def dfs(M, visited, i):
    for col in range(len(M)):
        if M[i][col] == 1 and not visited[col]:
            visited[col] = 1
            dfs(M, visited, col)
```