Skip to content

Instantly share code, notes, and snippets.

@msimpson msimpson/Twitter Problem Secret
Created Oct 30, 2013

Embed
What would you like to do?
var arr = [2,5,1,3,1,2,1,7,7,6,5,9,0,1,0,0,20,18,5,20,0,1,0,1];
function getPuddleVolume(arr) {
var max = Math.max.apply(null, arr),
volume = 0;
for (var y = 1; y <= max; y++) {
var inside = false,
gaps = 0;
for (var x = 0; x < arr.length; x++) {
if (arr[x] >= y) {
if (inside) {
inside = false;
volume += gaps;
x--;
} else {
inside = true;
gaps = 0;
}
} else {
gaps++;
}
}
}
return volume;
}
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.