Created
September 13, 2019 07:06
-
-
Save namthatman/b36ab3c9714a5e2be1ddff2ce5a3cd0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
def prison(n,m,h,v): | |
largest_h_gap = 1 | |
largest_v_gap = 1 | |
v_cell = [1] * m | |
h_cell = [1] * n | |
if len(h) == 0 and len(v) == 0: | |
return largest_h_gap * largest_v_gap | |
for vi in v: | |
v_cell[vi-1] = 0 | |
for hi in h: | |
h_cell[hi-1] = 0 | |
temp_gap = 1 | |
for i in range(len(v_cell)): | |
if v_cell[i] == 1: | |
temp_gap = 1 | |
if v_cell[i] == 0: | |
temp_gap = temp_gap + 1 | |
if temp_gap > largest_v_gap: | |
largest_v_gap = temp_gap | |
temp_gap = 1 | |
for i in range(len(h_cell)): | |
if h_cell[i] == 1: | |
temp_gap = 1 | |
if h_cell[i] == 0: | |
temp_gap = temp_gap + 1 | |
if temp_gap > largest_h_gap: | |
largest_h_gap = temp_gap | |
return largest_h_gap * largest_v_gap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment