Skip to content

Instantly share code, notes, and snippets.

@ThomasHigginson
Created March 31, 2022 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasHigginson/75dbe74a8ec1c50807b475bd0a65ca61 to your computer and use it in GitHub Desktop.
Save ThomasHigginson/75dbe74a8ec1c50807b475bd0a65ca61 to your computer and use it in GitHub Desktop.
maxLefts, maxRights = [0] * len(height), [0] * len(height)
# Maxs set to edges
maxLefts[0] = height[0]
maxRights[len(height)-1] = height[len(height)-1]
i, j = 1, len(height)-2
while i < len(height):
maxLefts[i] = max(maxLefts[i-1], height[i]) # Check this height to max height to left
maxRights[j] = max(maxRights[j+1], height[j]) # Check this height to max height to right
i += 1
j -= 1
# ... and now we have the max height to the left and right for each element
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment