Skip to content

Instantly share code, notes, and snippets.

@andreasnilsson
Created January 11, 2014 22:07
Show Gist options
  • Save andreasnilsson/8377601 to your computer and use it in GitHub Desktop.
Save andreasnilsson/8377601 to your computer and use it in GitHub Desktop.
__author__ = 'Enighma'
data = [2, 5, 1, 2, 3, 4, 7, 7, 6]
data = [2, 5, 1, 3, 1, 2, 1, 7, 7, 6]
class Point:
x=0
y=0
def Point(self, x, y):
self.x = x
self.y = y
# find first top
localMax = (-1, -1)
maxPoints = []
for i in range(0, len(data) - 1):
p = Point()
this = data[i]
if this > localMax[1]:
localMax = i, this
else:
if len(maxPoints) > 1:
maxPoints[1] = max(maxPoints[1], localMax)
else:
maxPoints.append(localMax)
localMax = (-1, -1)
max_water_height = min(maxPoints)
first = maxPoints[0]
second = maxPoints[1]
height = min(first[1], second[1])
width = second[0] - first[0] - 1
max_volume = height * width
subtract_volume = sum(data[first[0] + 1: second[0]])
print "volume", max_volume
print "sub vol.", subtract_volume
print "final volume", max_volume - subtract_volume
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment