You are viewing a single comment's thread. Return to all comments →
Javascript
function largestRectangle(heights) { let max = 0 for (let i = 0; i < heights.length; i++) { let toLeft = 0, toRight = 0 while (i - toLeft - 1 >= 0 && heights[i - toLeft - 1] >= heights[i]) toLeft++ while (i + toRight + 1 < heights.length && heights[i + toRight + 1] >= heights[i]) toRight++ max = Math.max(max, heights[i] * (1 + toLeft + toRight)) } return max }
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 →
Javascript