← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Given a 2D grid consisting of 0s (water) and 1s (land), an island is a maximal 4-directionally connected group of 1s. Two islands are considered distinct if their shapes are different when translated (rotations and reflections are not allowed). The task is to return the number of distinct islands, where islands with identical shape but different positions are counted only once. To determine uniqueness, the shape of each island is encoded as a normalized path string obtained by performing a DFS or BFS starting from the top-leftmost cell of the island and recording the relative coordinates or directions of all its cells.