FunctionRacerProblemsRace

Island Shapes

HardGridsPython, JavaScript, TypeScript, Java, C++

grid is a map of 1 (land) and 0 (water). An island is a group of land cells joined side by side.

Two islands have the same shape if one of them can be laid exactly over the other after sliding it, turning it by quarter turns and flipping it over, in any combination.

Return the number of different island shapes on the map.

Example 1

grid [[1,1,0,0],[1,0,0,1],[0,0,1,1]]
returns 1

Both islands are a corner piece of three cells. A half turn lays one over the other.

Example 2

grid [[1,1,1],[0,0,0],[1,0,1]]
returns 2

A bar of three cells and two single cells: two shapes.

Example 3

grid [[0]]
returns 0

There is no land.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Grids problems