You are viewing a single comment's thread. Return to all comments →
Python3 solution:
def twoPluses(grid): m, n = len(grid), len(grid[0]) sets = [] good = {(i,j) for (i,j) in product(range(m), range(n)) if grid[i][j] == "G"} for (i, j) in good: cur_set = {(i,j)} sets.append(cur_set) left, right = (i, j - 1), (i, j + 1) up, down = (i + 1, j), (i - 1, j) while True: if left not in good or right not in good: break if up not in good or down not in good: break for d in [left, right, up, down]: cur_set.add(d) sets.append(cur_set.copy()) left, right = (left[0], left[1] - 1), (right[0], right[1] + 1) up, down = (up[0] + 1, up[1]), (down[0] - 1, down[1]) mx = 0 for c1, c2 in product(sets, sets): if not c1.intersection(c2): sz = len(c1) * len(c2) if sz > mx: mx = sz return mx
Seems like cookies are disabled on this browser, please enable them to open this website
Ema's Supercomputer
You are viewing a single comment's thread. Return to all comments →
Python3 solution: