Largest rectangle in a histogram
Hardstackmonotonic stackarray
heights are bars of width 1 placed side by side. Return the area of the largest rectangle that fits inside them.
Example 1
Input: heights = [2,1,5,6,2,3] Output: 10
Bars 5 and 6: height 5 × width 2 = 10.
Example 2
Input: heights = [2,4] Output: 4
Constraints
- 1 ≤ heights.length ≤ 10⁵
- 0 ≤ heights[i] ≤ 10⁴
Submit checks your solution against 10 tests, including hidden ones.
/**
* @param {int[]} heights
* @return {int}
*/
function largestRectangleArea(heights) {
}