We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
deftwoPluses(grid):# Write your code heren=len(grid)m=len(grid[0])pluses=[]# finding all the possible crossesforrinrange(n):forcinrange(m):# setting the possible sizes for drawing crosses in each cellforiinrange(min(r,c,n-r-1,m-c-1)+1):# checking whether all cells for crosses are goodifall(grid[j][c]=='G'forjinrange(r-i,r+i+1)) \
andall(grid[r][k]=='G'forkinrange(c-i,c+i+1)):# record all the coordinates of the valid crossh_line=set((r,x)forxinrange(c-i,c+i+1))v_line=set((y,c)foryinrange(r-i,r+i+1))pluses.append(h_line|v_line)pluses=sorted(pluses,key=len,reverse=True)# finding the maximum product of 2 crossesmax_2=0whilelen(pluses)>1:plus_a=pluses.pop(0)forplus_binpluses:# check whether the 2 crosses are not overlappedifplus_a.isdisjoint(plus_b):max_2=max(max_2,len(plus_a)*len(plus_b))returnmax_2
Ema's Supercomputer
You are viewing a single comment's thread. Return to all comments →
My Python solution: