Compute island size in grid | Apple Interview Question