Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
walls = [2,5,1,3,1,2,1,7,7,6]
lmax = 0
rmax = 0
total = 0
#find rmax
for i in range(0, len(walls)):
if walls[i] > walls[rmax]:
rmax = i
#find lmax
for i in range(0, len(walls)):
if walls[i] > walls[lmax] and walls[i] <= walls[rmax] and i < rmax:
lmax = i
#ensure we have the proper ordering
if rmax < lmax:
lmax, rmax = rmax, lmax
maxheight = walls[rmax] if walls[rmax] < walls[lmax] else walls[lmax]
l = walls[lmax + 1:rmax]
for i in l:
total += (maxheight - i)
print total
@joist

This comment has been minimized.

Copy link

joist commented Oct 30, 2013

[2,5,1,3,1,2,1,1,5,5] bamboozles it.

@kalyan02

This comment has been minimized.

Copy link

kalyan02 commented Oct 31, 2013

Doesn't work for [2,1,3,1,3]

  X X
X X X
XXXXX

Expected: 3
Result: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.