Skip to content

Instantly share code, notes, and snippets.

@gurdeep999
Last active November 16, 2020 10:06
Show Gist options
  • Save gurdeep999/84596e47e1d3b83ca0135542c290c715 to your computer and use it in GitHub Desktop.
Save gurdeep999/84596e47e1d3b83ca0135542c290c715 to your computer and use it in GitHub Desktop.
def maxHeight(wallPositions, wallHeights):
# Write your code here
n = len(wallPositions)
mud_max = 0
for i in range(0, n - 1):
if wallPositions[i] < (wallPositions[i + 1] - 1):
# We have a gap
heightDiff = abs(wallHeights[i + 1] - wallHeights[i])
gapLen = wallPositions[i + 1] - wallPositions[i] - 1
localMax = 0
if gapLen > heightDiff:
low = max(wallHeights[i + 1], wallHeights[i]) + 1
remainingGap = gapLen - heightDiff - 1
localMax = low + remainingGap / 2
else:
localMax = min(wallHeights[i + 1], wallHeights[i]) + gapLen
mud_max = max(mud_max, localMax)
return int(mud_max)
wall_pos = [1, 10]
wall_height = [1, 5]
print(maxHeight(wall_pos, wall_height))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment