Created
October 22, 2016 02:16
-
-
Save kartikkukreja/0fa18a83633b9d30d9afa91b02cb4c5b to your computer and use it in GitHub Desktop.
Largest rectangle in a histogram naive solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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