# Number of Distinct Islands

Problem Link: <https://practice.geeksforgeeks.org/problems/number-of-distinct-islands/1>

```python
import sys
from typing import List
sys.setrecursionlimit(10**8)
class Solution:

    def countDistinctIslands(self, grid : List[List[int]]) -> int:
        # code here
        
        def dfs(i,j,m,n,grid,visited,i0,j0,s):
            
            if(i<0 or j<0 or i>=m or j>=n or visited[i][j]==1 or grid[i][j]==0):
                return
            
            # Lists cannot be hashed
            temp.append((i-i0,j-j0))
                
            visited[i][j]=1
            
            dfs(i-1,j,m,n,grid,visited,i0,j0,s)
            dfs(i,j-1,m,n,grid,visited,i0,j0,s)
            dfs(i+1,j,m,n,grid,visited,i0,j0,s)
            dfs(i,j+1,m,n,grid,visited,i0,j0,s)
        
        m=len(grid)
        n=len(grid[0])
        s={}
        c=0
        visited=[[0 for i in range(n)] for j in range(m)]
        for i in range(m):
            for j in range(n):
                if(grid[i][j]==1 and visited[i][j]==0):
                    temp=[]
                    dfs(i,j,m,n,grid,visited,i,j,s)
                    # Lists cannot be hashed
                    if(tuple(temp) not in s):
                        s[tuple(temp)]=1
                    else:
                        s[tuple(temp)]+=1

        return len(s)
```
