39. Largest rectangle in a histogram
Given an array of integers heights representing the histogram's bar height where the width of each bar is 1Â return the area of the largest rectangle in the histogram.
Example 1:
Input: heights = [2, 1, 5, 6, 2, 3]
Output: 10
Explanation: The largest rectangle is highlighted, which has an area of 5*2 = 10 units.
Example 2:
Input: heights = [3, 5, 1, 7, 5, 9]
Output: 15
Explanation: The largest rectangle has an area of 5*3 = 15 units.
Now Your Turn!
Pick the correct output for the given inputInput: heights = [2,4]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- Â Â 1 <= heights.length <= 105
- Â Â 0 <= heights[i] <= 104