chart of zeros and ones: 1 is land, 0 is water. An island is a group of land cells connected through their sides (horizontally or vertically; diagonal neighbours do not count). Everything outside the map is water.
Two islands have the same shape if one can be laid over the other by a shift combined with a rotation by 90°, 180° or 270° and/or a mirror reflection.
Return the number of distinct shapes among all the islands on the map.chart=[[1, 1, 1, 0], [0, 0, 1, 0], [0, 0, 0, 0], [1, 0, 0, 0], [1, 1, 1, 0]] → 1
Both islands are four-cell corners: the lower one is the upper one rotated by 180°. One shape.
chart=[[1, 1, 0, 1], [0, 1, 0, 1], [0, 0, 0, 1], [1, 0, 0, 0]] → 3
A three-cell corner, a three-cell vertical strip and a single cell are three different shapes: no rotation or reflection matches them.
chart=[[1, 0, 1], [0, 0, 0], [1, 0, 1]] → 1
chart[i][j] is 0 or 1chart=[[1, 1, 1, 0], [0, 0, 1, 0], [0, 0, 0, 0], [1, 0, 0, 0], [1, 1, 1, 0]]
1
Run checks the first 3 tests in your browser. Submit checks all 80 tests on the server, hidden ones included.