• + 1 comment

    My Python solution:

    def twoPluses(grid):
        # Write your code here
        n = len(grid)
        m = len(grid[0])
        pluses = []
        # finding all the possible crosses
        for r in range(n):
            for c in range(m):
                # setting the possible sizes for drawing crosses in each cell
                for i in range(min(r, c, n - r - 1, m - c - 1) + 1):
                    # checking whether all cells for crosses are good
                    if all(grid[j][c] == 'G' for j in range(r - i, r + i + 1)) \
                    and all(grid[r][k] == 'G' for k in range(c - i, c + i + 1)):
                        # record all the coordinates of the valid cross
                        h_line = set((r, x) for x in range(c - i, c + i + 1))
                        v_line = set((y, c) for y in range(r - i, r + i + 1))
                        pluses.append(h_line | v_line)
        pluses = sorted(pluses, key = len, reverse = True)
        # finding the maximum product of 2 crosses
        max_2 = 0
        while len(pluses) > 1:
            plus_a = pluses.pop(0)
            for plus_b in pluses:
                # check whether the 2 crosses are not overlapped
                if plus_a.isdisjoint(plus_b):
                    max_2 = max(max_2, len(plus_a) * len(plus_b))
        return max_2