diff --git a/Uncategorized/Largest Rectangle In Histogram/README.md b/Uncategorized/Largest Rectangle In Histogram/README.md new file mode 100644 index 00000000..5fc804fe --- /dev/null +++ b/Uncategorized/Largest Rectangle In Histogram/README.md @@ -0,0 +1,11 @@ +# Largest Rectangle In Histogram + +Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram. + +## Example: +![plot](./histogram.jpg?raw=true) + +Input: heights = [2,1,5,6,2,3] +Output: 10 +Explanation: The above is a histogram where width of each bar is 1. +The largest rectangle is shown in the red area, which has an area = 10 units. \ No newline at end of file diff --git a/Uncategorized/Largest Rectangle In Histogram/histogram.jpg b/Uncategorized/Largest Rectangle In Histogram/histogram.jpg new file mode 100644 index 00000000..3e9fc83a Binary files /dev/null and b/Uncategorized/Largest Rectangle In Histogram/histogram.jpg differ diff --git a/Uncategorized/Largest Rectangle In Histogram/largest.cpp b/Uncategorized/Largest Rectangle In Histogram/largest.cpp new file mode 100644 index 00000000..4314c6b3 --- /dev/null +++ b/Uncategorized/Largest Rectangle In Histogram/largest.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +using namespace std; + +vector nearestSmallerOnRight(vector& heights) { + stackst; + vectorans(heights.size(),heights.size()); + for(int i=0;i nearestSmallerOnLeft(vector& heights) +{ + stackst; + vectorans(heights.size(),-1); + for(int i=heights.size()-1;i>=0;i--) + { + while(!st.empty() && heights[i]& heights) +{ + vectorNSR=nearestSmallerOnRight(heights); + vectorNSL=nearestSmallerOnLeft(heights); + int ans=0; + for(int i=0;i vec = {2, 1, 5, 6, 2, 3}; + cout << largestRectangleArea(vec); +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy