Skip to content

Instantly share code, notes, and snippets.

@goish135
Created August 29, 2021 19:19
Show Gist options
  • Save goish135/f09c7ac9cbdee7511c54c04326b82a2b to your computer and use it in GitHub Desktop.
Save goish135/f09c7ac9cbdee7511c54c04326b82a2b to your computer and use it in GitHub Desktop.
pos = [1,2,4,7]
height = [4,6,8,10]
maxLeft = [0]*(max(pos)+1)
maxRight = [0]*(max(pos)+1)
# min(left,right)+1
total = [0]*(max(pos)+1)
#print(len(total))
for i in range(len(pos)):
total[pos[i]]=height[i]
#print(total)
#print(len(total))
maxH = -1
for j in range(1,len(total)):
if total[j]==0:
#print(j)
Left = -1
Right = -1
for k in range(j-1,-1,-1):
if total[k]!=0:
Left = total[k]
break
for z in range(j+1,len(total)):
if total[z]!=0:
Right = total[z]
break
#print(min(Left,Right)+1)
total[j] = min(Left,Right)+1
if total[j] > maxH:
maxH = total[j]
print(maxH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment