Quant Memo
Coding/●●●●●

Count the distinct island shapes

Given a binary grid of land (1) and water (0), count the number of distinct island shapes. Two islands have the same shape if one can slide onto the other by translation only (no rotation or reflection).

grid = [[1, 1, 0, 1, 1],
        [1, 0, 0, 0, 1],
        [0, 0, 0, 0, 0],
        [1, 1, 0, 0, 0],
        [1, 0, 0, 0, 0]]
-> 2

Return the count of distinct shapes. Aim for O(nm)O(nm).

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions