Largest Rectangle in Histogram

Hard
Arrays Stack Monotonic Stack
Find the largest rectangle in a histogram. Input: space-separated heights Output: max area

Constraints

See problem-specific constraints. Optimized solution required.

Examples

Example 1:
Input: 2 1 5 6 2 3
Output:
Example 2:
Input: 2 1 5 6 2 3
Output:

Hints

Consider a stack approach.
Think about time complexity.
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.