Largest histogram rectangle

Write codeHard30 min

Your task

Given the heights of bars in a histogram (each bar has width 1), find the area of the largest axis-aligned rectangle that fits entirely within the histogram. Return that maximum area. Constraints: 0 <= n <= 10^5, 0 <= height[i] <= 10^4.

Examples

largest_rectangle(heights: list[int]) -> int
Example 1
Inputlargest_rectangle([2, 1, 5, 6, 2, 3])
Output10