Largest Rectangle in Histogram Problem

Largest Rectangle in Histogram Problem — ExecCode Medium DSA Practice

Solve the Largest Rectangle in Histogram problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

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, 4, 1]; Output 10. Input heights = [2, 1, 5, 6, 2, 3]; Output 10

Constraints

1 ≤ heights.length ≤ 10⁵ 0 ≤ heights[i] ≤ 10⁴

Practice Largest Rectangle in Histogram free on ExecCode. Browse DSA problems, topic map, and placement guides.