Largest Rectangle in Histogram Problem Statement
You are given an array/list HEIGHTS
of length N
, where each element represents the height of a histogram bar. The width of each bar is considered to be 1.
Your task is to compute the area of the largest rectangle that can be formed within the bounds of the given histogram.
Example:
Input:
{2, 1, 5, 6, 2, 3}
Output:
10
Explanation:
In the given histogram, the largest rectangle possible has an area of 10.
Input:
The first line contains a single integer 'T’, representing the number of test cases. For each test case, the first line contains a single integer 'N' representing the number of elements in the array/list. The second line contains 'N' single space-separated integers, denoting the elements of the array/list HEIGHTS.
Output:
For each test case, output an integer that represents the area of the largest rectangle possible in the given histogram.
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 10^6
0 ≤ HEIGHTS[i] ≤ 10^9
- Time Limit: 1 sec.
Note:
You do not need to print anything; it has already been taken care of. Just implement the given function.
Be the first one to answer
Add answer anonymously...
Top Cult.fit Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app