Problem
You get an array of integers heights. The array describes a histogram. A histogram is a chart of bars that stand next to each other on a base line.
Each bar has a width of 1, and bar i has the height heights[i]. Return the area of the largest rectangle that fits completely inside the bars of the histogram.
Example 1
- Input:
- heights = [3,1,4,4,2]
- Output:
- 8
- Explanation:
- The two bars with the height 4 make a rectangle with the width 2 and the height 4. Its area is 8.
Example 2
- Input:
- heights = [2,3,2]
- Output:
- 6
- Explanation:
- A rectangle with the height 2 covers all three bars. Its area is 6.
Example 3
- Input:
- heights = [0,7,0]
- Output:
- 7
Constraints
- 1 <= heights.length <= 10^5
- 0 <= heights[i] <= 10^4
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- 132 Pattern
Coding · Array · Binary Search · Monotonic Stack
- Beautiful Towers II
Coding · Array · Monotonic Stack · Stack
- Binary Searchable Numbers in an Unsorted Array
Coding · Array · Binary Search · Monotonic Stack
- Buildings With an Ocean View
Coding · Array · Monotonic Stack · Stack
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 84. Largest Rectangle in Histogram
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 2 records
Bloomberg
Largest Rectangle in Histogram
Reported date not specified · Source window: 30d
Source snapshot: Oct 20, 2026
Source frequency score: 59.6. This is not an interview probability.
View sourceMicrosoft
Largest Rectangle in Histogram
Reported date not specified · Source window: 3mo
Source snapshot: Oct 20, 2026
Source frequency score: 56.3. This is not an interview probability.
View source