Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kartikkukreja/0fa18a83633b9d30d9afa91b02cb4c5b to your computer and use it in GitHub Desktop.
Save kartikkukreja/0fa18a83633b9d30d9afa91b02cb4c5b to your computer and use it in GitHub Desktop.
Largest rectangle in a histogram naive solution
int largestRectangleArea(vector<int> &A) {
int maxArea = 0;
for (int i = 0; i < A.size(); i++) {
for (int j = i, mn = A[i]; j < A.size(); j++) {
mn = min(mn, A[j]);
maxArea = max(maxArea, (j-i+1) * mn);
}
}
return maxArea;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment