Created
October 30, 2013 12:51
-
-
Save Shruubi/7232152 to your computer and use it in GitHub Desktop.
quick, bored solution to http://qandwhat.apps.runkite.com/i-failed-a-twitter-interview/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
[2,5,1,3,1,2,1,1,5,5] bamboozles it.