For every integer j between f[i] and i, we have height[j] >= height[i]. For every integer j between i and b[i], we have height[j] >= height[i]. And of course, among all possible integers, f[i] is the smallest one while b[i] is the largest one.

I think the time complexity of this algorithm is O(n), but I'm not sure.

```
int largestRectangleArea(vector<int> &height) {
int n = height.size();
if (n == 0) return 0;
vector<int> f(n), b(n);
f[0] = -1;
for (int i = 1; i < n; ++ i) {
f[i] = i-1;
while (f[i] != -1 && height[f[i]] >= height[i]) {
f[i] = f[f[i]];
}
}
b[n-1] = n;
for (int i = n-2; i > -1; -- i) {
b[i] = i+1;
while (b[i] != n && height[b[i]] >= height[i]) {
b[i] = b[b[i]];
}
}
int maxval = height[0];
for (int i = 1; i < n; ++ i) {
maxval = max(maxval, height[i]*(b[i]-f[i]-1));
}
return maxval;
}
```