You are viewing a single comment's thread. Return to all comments →
JS code :
function largestRectangle(h) { let largest = 0; let n = h.length; for(let i = 0; i < n ; i++){ let counter = 1; for(let j = i - 1; j >= 0 ; j--){ if(j < 0 || h[j] < h[i]){ break; } counter++; } console.log(h[i] + ' : ' + counter); let temp = i + 1; while(h[temp] >= h[i] && i < n){ counter++; temp++; } if(h[i] * counter > largest) largest = h[i] * counter; } return largest; }
Seems like cookies are disabled on this browser, please enable them to open this website
Largest Rectangle
You are viewing a single comment's thread. Return to all comments →
JS code :