Skip to content

Instantly share code, notes, and snippets.



Last active Dec 31, 2015
What would you like to do?
Twitter interview question
function mySolution(walls){
var heightLoc = {};
var waterSum = 0;
for(var x=0; x<walls.length; x++){
for(var y=0; y<walls[x]; y++){
var height = y+'';
waterSum += height in heightLoc ? (x - heightLoc[height]) - 1 : 0;
heightLoc[height] = x; // record last time we saw a wall of this height
return waterSum;
var walls = [2,5,1,3,1,2,1,7,1,5,1];
var myResult = mySolution(walls);
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.