class Solution
{
public:
//Function to find largest rectangular area possible in a given histogram.
long long getMaxArea(long long arr[], int n)
{
stack<int> s;
int max_area=0;
int i=0;
while(i<n)
{
while(!s.empty() and arr[i]<arr[s.top()])
{
int t=s.top();
int h=arr[t];
s.pop();
if(s.empty())
{
max_area=max(max_area,h*i);
}
else
{
max_area=max(max_area,h*(i-t-1));
}
}
s.push(i); //It also handles the insertion of the first element
i++;
}
return max_area;
}
};