Dsa
Stack
Hard
Largest Rectangle in Histogram
Given an array of integers where each integer represents the height of a histogram bar, write a program to find the area of the largest rectangle that can be formed in the histogram. Bars are adjacent to each other in the array. Use a stack to determine the largest rectangle area efficiently.
Input format:
A single line with space-separated integers representing the histogram heights.
Output format:
Print a single integer representing the area of the largest rectangle.
Example:
Input:
2 1 5 6 2 3
Output:
10
Key concepts
stackmax_areahistogram
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now