You are viewing a single comment's thread. Return to all comments →

Not the best algorithm, but works anyway!

let area = 0; for(let i = 0; i < h.length; i++){ let height = h[i] let length = 1 let area1 = 0; let area2 = 0; let j = i+1; //forward traversal while(j < h.length){ if(height > h[j])break if(height <= h[j])length++ j++ } area1 = (height*length); j = i-1; length = 1; // Backward Traversal while(j >= 0){ if(height > h[j])break if(height <= h[j])length++ j--; } area2 = (height*(length-1)); if(area < (area1+area2))area = (area1+area2) } return area;

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 →

Not the best algorithm, but works anyway!