Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Speedy category for Spaceship Landing Strip by takapt0226
# O(H * W)
def checkio(landing_map):
H = len(landing_map)
W = len(landing_map[0])
max_area = 0
height = [0] * (W + 1)
for y in range(H):
for x in range(W):
if landing_map[y][x] in 'GS':
height[x] += 1
else:
height[x] = 0
sta = []
sta.append((-1, -1))
for x in range(W + 1):
while sta[-1][1] >= height[x]:
_, h = sta.pop()
left = sta[-1][0]
max_area = max(max_area, h * (x - left - 1))
sta.append((x, height[x]))
return max_area
Feb. 27, 2014
Comments: