As I suggested earlier, it's easier to work out the solution if you could build up a right data structure to contain all number of consecutive dots first, then work from there. Here is the sample code to show this: (part1 answer here, part 2- leave as your exercise) This code is adopted from another S/O posts (@AlainT), and modify to suite this question/format accordingly.
(BTW - your code sample did not work at all, maybe the format issue?)
def bigSquare(matrix):
spanSize = [ list(map(len,row.split("o"))) for row in matrix ]
# print([s for ss in spanSize for s in ss if s>0]) # your array of numbers
spans = [ [c for s in ss
for c in range(s,-1,-1)]
for ss in spanSize
]
#print(f' spans: {spans} ')
result = (0,0,0,0,0) # area, height, width, top, left
for r,row in enumerate(spans):
for c in range(len(row)):
nextSpans = accumulate( (spanRow[c] for spanRow in spans[r:]),min)
rectSize = max( [(w*h,h,w) for h,w in enumerate(nextSpans,1)] )
print(r, c, rectSize)
result = max(result,rectSize+(r,c))
return result[0] # return the Square Area
if __name__ == '__main__':
matrix =['...o..o.o',
'...oo....',
'...o....o',
'..o.ooo..',
'o...o....',
'.oo......', # <--- start
'..o....o.',
'.oo......',
'.........']
print(bigSquare(matrix)) # Output: 16