class Solution {
public:
void print (vector<int> array)
{
for (int i=0;i<array.size();i++)
{
cout<<array[i]<<" ";
}
cout<<endl;
}
vector<int> nsr(vector<int> heights)
{
int n = heights.size();
vector<int> v(n);
stack <pair<int,int>> s;
for (int i=0 ;i<n;i++)
{
if (s.size()== 0)
{
v.push_back(-1);
}
else if (s.size()>0 && s.top().first<= heights[i])
{
v.push_back (s.top().second);
}
else if (s.size()>0 && s.top().first >=heights[i])
{
while (s.size()>0 && s.top().first>= heights[i])
{
s.pop();
}
if (s.size() == 0)
v.push_back(-1);
else
v.push_back (s.top().second);
}
s.push({heights[i], i});
}
return v ;
}
vector<int> nsl(vector<int> heights)
{
int n = heights.size();
vector<int> v(n);
print(v);
stack <pair<int,int>> s;
for (int i=n-1; i>=0;i--)
{
if (s.size()== 0)
{
v.push_back(n);
}
else if (s.size()>0 && s.top().first<= heights[i])
{
v.push_back (s.top().second);
}
else if (s.size()>0 && s.top().first >=heights[i])
{
while (s.size()>0 && s.top().first>= heights[i])
{
s.pop();
}
if (s.size()== 0)
v.push_back(n);
else
v.push_back (s.top().second);
}
s.push({heights[i], i});
}
// print (v);
return v;
}
int largestRectangleArea(vector<int>& heights) {
vector<int> width ;
vector <int> left= nsl(heights);
left.reverse(left.begin(),left.end());
vector <int> right = nsr(heights);
// print(left);
// print(right);
for (int i = 0 ;i< heights.size()-1;i++)
{
int element = left[i] - right[i] - 1;
width.push_back (element);
}
int area = INT_MIN;
for (int i =0 ;i<heights.size()-1;i++)
{
int newarea = heights[i]* width[i];
area = max(area, newarea);
//cout<< area <<endl;
}
return area ;
}
};
I am using reverse() in vector but it's showing an error. I have tried using header files but the error is same. I had used reverse with vector many times but it never gave an error.
Error :
Line 80: Char 14: error: no member named 'reverse' in 'std::vector<int, std::allocator>' left.reverse(left.begin(),left.end());