Skip to content

Instantly share code, notes, and snippets.

@Shruubi
Created October 30, 2013 12:51
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 Shruubi/7232152 to your computer and use it in GitHub Desktop.
Save Shruubi/7232152 to your computer and use it in GitHub Desktop.
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
Copy link

joist commented Oct 30, 2013

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

@kalyan02
Copy link

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