cheetcode

27. Largest Rectangle in HistogramHard

Find the area of the largest rectangle that can be formed 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.

Examples

Input: heights = [2,1,5,6,2,3]
Output: 10
Input: heights = [2,4]
Output: 4

Constraints

  • 1 <= heights.length <= 100,000
  • 0 <= heights[i] <= 10,000