Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Enumerate and index solution in Clear category for Ground for the House by kkkkk
def house(plan):
"""Calculate area for house by looking for '#' in rows of plan."""
rows = plan.split()
start_row = -1
end_row = 0
min_start_idx = len(rows[0])
max_start_idx = 0
for idx, row in enumerate(rows):
if '#' in row:
min_start_idx = min(min_start_idx, row.index('#'))
max_start_idx = max(max_start_idx, row.rindex('#'))
if start_row < 0:
start_row = idx
end_row = idx
if start_row < 0:
return 0
return((end_row - start_row) + 1) * ((max_start_idx - min_start_idx) + 1)
Sept. 25, 2019
Comments: