Largest Rectangle in Histogram

IF
AlgoAxiomStaff Engineers
JSTS
Hard20 mins

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

Example 1:

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

Output: 10

Explanation: The largest rectangle has an area of 10 units (formed by heights 5 and 6).

Example 2:

Input: heights = [2,4]

Output: 4

Constraints

  • 1 <= heights.length <= 10^5
  • 0 <= heights[i] <= 10^4
Source: Stacks pattern — AlgoAxiom
JavaScript
Test Case 1
root = [1, 2, 3]
Test Case 2
root = [1, 2, 3, 4, 5]
Idle