Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tcw165/ce49b7464b0572a97e745a23c23897a7 to your computer and use it in GitHub Desktop.
Save tcw165/ce49b7464b0572a97e745a23c23897a7 to your computer and use it in GitHub Desktop.
public int largestRectanglularAreaInHistogram(int[] hist) {
int maxArea = 0;
// Iterate through the histogram.
for (int i = 0; i < hist.length; ++i) {
int h = hist[i];
maxArea = Math.max(maxArea, h);
for (int j = i - 1; j >= 0; --j) {
final int w = (i - j + 1);
h = Math.min(h, hist[j]);
maxArea = Math.max(maxArea, h * w);
}
}
return maxArea;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment