id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
2
{ "code": "class Solution {\npublic:\n vector<int> nextSmall(vector<int> &arr){\n vector<int> sol(arr.size());\n stack<int> st;\n st.push(-1);\n for(int i = arr.size()-1; i>=0; i--){\n while(st.top()!=-1 && arr[st.top()]>=arr[i]){\n st.pop();\n }\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
2
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n=heights.size();\n vector<int>nextSmaller(n,n-1);\n stack<int>st;\n for(int i=0;i<n;i++){\n int curr=heights[i];\n while(!st.empty()&&curr<heights[st.top()]){\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
2
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& nums) {\n\n int n = nums.size();\n vector<int> prev(n, -1), next(n, n);\n stack<int> sk;\n\n auto print = [](auto nums){\n for(auto a: nums)\n cout<<a<<\"\\t\";\n cout<<endl...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
2
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n=heights.size();\n stack<int>st;\n vector<int>right(n,n);\n vector<int>left(n,-1);\n for(int i=0;i<n;i++){\n while(!st.empty()&&heights[st.top()]>heights[i]){\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
2
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n // Here goes a function\n int largestRectangleArea(vector<int> &heights) {\n stack<int> next_lower;\n vector<pair<int, int>> limits(heights.size());\n for (int i = 0; i < heights.size(); ++i) {\n while (!next_lowe...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n std::vector<int> rightBound(heights.size(), heights.size() - 1);\n std::vector<int> leftBound(heights.size(), 0);\n\n std::stack<int> stR;\n for (int i = 0; i < heights.size(); i++) {\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> nextSmaller(vector<int>& heights, int n) {\n stack<int> st;\n vector<int> small(n,n);\n for (int i = 0; i < n; i++) {\n while (!st.empty() && heights[st.top()] > heights[i]) {\n int index = st.top();\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n const int n = heights.size();\n stack<int> s;\n vector<int> nextSmaller(n, n);\n for (int i = 0; i < n; i++) {\n while (!s.empty() && heights[s.top()] > heights[i]) { // found next small...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n vector<int> leftMin(heights.size(), -1);\n vector<int> rightMin(heights.size(), heights.size());\n\n vector<int> monotonicStack;\n for(auto i = 0; i < heights.size(); ++i) {\n if(monoton...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& nums) {\n int n = nums.size();\n vector<int> lse(n),pse(n);stack<pair<int,int>>st;\n\n for (int i = 0; i < n; i++) {\n while (!st.empty() && st.top().first >= nums[i]) {\n st.pop();\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n vector<int>right(heights.size(),heights.size());\n vector<int>left(heights.size(),-1);\n stack<int>st;\n for(int i =0;i<heights.size();i++){\n while(!st.empty() &&heights[st.top()] >heig...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<int> prevSmaller, nextSmaller(n);\n\n vector<pair<int,int>> st, st2;\n st.push_back({-1,-1});\n st2.push_back({-1,n});\n\n for(int i=0; i<n; i++)\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<int> prevSmaller, nextSmaller(n);\n\n vector<pair<int,int>> st;\n st.push_back({-1,-1});\n\n for(int i=0; i<n; i++)\n {\n while(!st.empty()...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int ans = 0;\n int r[100005],l[100005];\n priority_queue<pair<int,int>> pq;\n for(int i = 0; i < heights.size(); i++){\n if(pq.empty()){\n pq.push(make_pair(heights[i],i))...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n\n int n = heights.size();\n\n vector<int> width(n, 1);\n\n stack<pair<int,int>> q;\n \n int i;\n for(i = 0; i<n; i++){\n while(!q.empty() && q.top().first > heights[i]) {\...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n vector<int> lefts;\n stack<int> next_sm;\n\n for(int i =0; i<heights.size(); i++){\n if(next_sm.empty()){\n lefts.push_back(i);\n next_sm.push(i);\n }el...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n\n stack<int> ns;\n stack<int> ps;\n int len = heights.size();\n\n vector<int> nxtsml(len, 0);\n vector<int> presml;\n\n ns.push(-1);\n\n for(int i=0;i<len;i++){\n\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> pse(vector<int> & arr){\n int n=arr.size();\n vector<int> v;\n stack<int> st;\n for(int i=0;i<n;i++){\n while(!st.empty() && arr[st.top()]>=arr[i]){\n st.pop();\n }\n if(st.empty()){\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n void findnextsmall(vector<int> &heights, vector<int>&nextsmall, stack<int>&s2)\n {\n nextsmall[heights.size()-1]=heights.size();\n s2.push(heights.size()-1);\n\n for(int i=heights.size()-2; i>=0; i--)\n {\n if(hei...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\nprivate:\n vector<int> prevSmaller(vector<int>& heights) {\n int n = heights.size();\n vector<int> res(n, -1);\n stack<pair<int, int>> stk; // idx, val\n for (int i = 0; i < n; i++) {\n while (!stk.empty() && stk.top().second >= heights[i]) {\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n long long int mod=1e9+7;\n int solve(vector<int>& arr) {\n vector<long long>v(arr.size(),0);\n stack<int>st;\n long long ans=0;\n int n=arr.size();\n v[n-1]=n;\n st.push(n-1);\n for(int i=n-2;i>=0;i--){\n while(!s...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> nextSmallerRight(vector<int>& heights) {\n // we need to iterate from the left hand side of the array\n int n = heights.size();\n stack<pair<int, int>> s;\n vector<int> v(n,n);\n for (int i = n - 1; i >= 0; i--) {\n wh...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\n private:\nvector<int> nextelement(vector<int>& heights, int n )\n{\n stack<int>st;\n st.push(-1);\n vector<int>ans(n);\n for(int i =n-1;i>=0;i--)\n {\n int curr= heights[i];\n while(st.top()!=-1 && heights[st.top()]>=curr)\n {\n st.pop();...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\nprivate:\nvector<int>nse_finder(vector<int>arr){\n vector<int>nse(arr.size());\n stack<int>st;\n for(int i=arr.size()-1;i>=0;i--){\n while(!st.empty() && arr[i]<=arr[st.top()]){\n st.pop();\n }\n if(st.empty()){\n nse[i]=arr.size();\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\nprivate:\n vector<int> prevfunc(vector<int>&heights, int n){\n vector<int> ans(n);\n stack<int> s;\n s.push(-1);\n for(int i = 0; i < n; i++){\n int curr = heights[i];\n while(s.top() != -1 && heights[s.top()] >= curr)s.pop();\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> nextSmallerElement(vector<int>& heights){\n int n = heights.size();\n vector<int>ans(n,n);\n stack<int>st;\n for(int i=n-1;i>=0;i--){\n while(!st.empty() && heights[i]<=heights[st.top()]){\n st.pop();\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> nextSmallerElement(vector<int>& heights,int n){\n stack <int> s;\n s.push(-1);\n vector<int> ans(n);\n for(int i=n-1; i>=0 ;i--){\n while (s.top() != -1 && heights[s.top()] >= heights[i]) \n {\n s.po...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& arr) {\n int n = arr.size();\n vector<long long> left(n,0);\n vector<long long> right (n,0);\n stack<long long> st1,st2;\n int mod = 1e9+7;\n for(int i=0;i<n;i++){\n while(!st1.empty() ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n\n vector<int> PSE(vector<int> nums){\n vector<int> result(nums.size() , -1);\n stack<pair<int,int>> st;\n for(int i = 0 ; i < nums.size() ; i++){\n\n while(!st.empty() && st.top().first >= nums[i]) st.pop();\n if(!st.empty()) result[...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n\n vector<int> PSE(vector<int> nums){\n vector<int> result(nums.size() , -1);\n stack<pair<int,int>> st;\n for(int i = 0 ; i < nums.size() ; i++){\n\n while(!st.empty() && st.top().first >= nums[i]) st.pop();\n if(!st.empty()) result[...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n void nextSmallerElement(vector<int>arr,vector<int>& nse,stack<int>st){\n int n = arr.size();\n for(int i=n-1;i>=0;i--){\n while(!st.empty() && arr[i]<=arr[st.top()])\n st.pop();\n if(!st.empty())\n nse[i]=st.to...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> calPosSmaller(vector<int>& heights) {\n vector<int> ret(heights.size(), 0);\n stack<int> st;\n st.push(0);\n int i = 1;\n while(i < heights.size()) {\n while(!st.empty()) {\n if (heights[i] < heights[st....
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n void nxtsmall(vector<int>&height,vector<int>&left,vector<int>&right){\n stack<int>st;\n st.push(-1);\n int n=height.size();\n for(int i=0;i<n;i++){\n while(st.top()!=-1&&height[st.top()]>height[i]){\n st.pop();\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<pair<int,int>> st;\n int n=heights.size();\n vector<int>left(n,-1);\n vector<int> right(n,n);\n //nse to right\n for(int i=n-1;i>=0;i--)\n {\n while(!st.empty(...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<int>arr = heights;\n vector<int> pse(n, -1); \n vector<int> nse(n, n); \n stack<pair<int, int>> s1; \n stack<pair<int, int>> s2; \n \n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<long long> nextSmallerElements(const vector<int>& heights) {\n int n = heights.size();\n vector<long long> v2(n);\n stack<pair<long long, int>> s;\n for (int i = n - 1; i >= 0; i--) {\n while (!s.empty() && s.top().first >= height...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack <pair<int, int>> s;\n int n = heights.size();\n vector<int> min_right(n, -1);\n vector<int> min_left(n, -1);\n s.push({heights[0], 0});\n for(int i = 1; i < n; i++){\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<long long>left(n);\n vector<long long>right(n);\n stack<pair <long long , long long >>st;\n stack<pair <long long , long long >>st1;\n for (int i = n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& nums) {\n stack<pair<int,int>> s1,s2;\n int n=nums.size();\n vector<int> v1(n),v2(n);\n int i=n-1;\n while(i>=0){\n if(s1.empty() || s1.top().first<=nums[i]){\n s1.push({nums[i]...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> pse (vector<int> heights) {\n stack<int> st;\n int n = heights.size();\n vector<int> result(n);\n\n for (int i = 0; i < n; i++) {\n while (!st.empty() && heights[st.top()] > heights[i])\n st.pop();\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> psei(vector<int>& arr){\n int n= arr.size();\n stack<int>st;\n vector<int> pse(n,0);\n for (int i=0; i<n; i++){\n while(!st.empty() && arr[st.top()] > arr[i]){\n st.pop();\n }\n pse[i]= st...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\n void cal(vector<int>& heights, vector<int>& ind) {\n int n = heights.size();\n stack<pair<int,int>> stk;\n for (int i=0; i < n; i++) {\n while (!stk.empty() && stk.top().second > heights[i]) {\n ind[stk.top().first] = i;\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\n void cal(vector<int>& heights, vector<int>& ind) {\n int n = heights.size();\n stack<pair<int,int>> stk;\n for (int i=0; i < n; i++) {\n while (!stk.empty() && stk.top().second > heights[i]) {\n ind[stk.top().first] = i;\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "int lsp(vector<int>& heights) {\n\n int n = heights.size();\n stack<int> a;\n\n vector<int> pref(n), suff(n);\n for (int i = 0; i < n; i++) {\n while (!a.empty() && heights[a.top()] >= heights[i])\n a.pop();\n\n if (a.empty())\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n\n\n int largestRectangleArea(vector<int>& heights) {\n vector<int>v1(heights.size() , heights.size());\n stack<pair<int , int> > s ; \n for (int i = heights.size()-1 ; i >= 0 ; i--)\n { \n while( !s.empty() && heights[i] <= s.top().first)...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& arr) {\n int n=arr.size();\n stack<pair<int,int>> st;\n\n vector<int> prefix(n),suffix(n);\n\n for(int i=0;i<n;i++)\n {\n int curr=arr[i];\n while(st.size()>0&&st.top().first>=curr)...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> nextSmallerElement(vector<int>height){\n stack<int> st;\n int n=height.size();\n vector<int> output(n,n);\n st.push(0); \n for(int i=0;i<n;i++){\n while(!st.empty() and height[st.top()]>height[i]){\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n void call1(const vector<int>& nums, vector<int>& right) {\n stack<int> st;\n for (int i = 0; i < nums.size(); ++i) {\n while (!st.empty() && nums[st.top()] > nums[i]) {\n right[st.top()] = i;\n st.pop();\n }\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> findNextSmallerElem(const vector<int>& v) {\n stack<int> st;\n st.push(-1);\n vector<int> ans;\n for (int i = v.size() - 1; i >= 0; i--) {\n while (st.top()!=-1&&v[st.top()] >= v[i]) {\n st.pop();\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n\n void nextSmallerElement(vector<int>& arr, vector<int>& nextAns) {\n stack<int> st;\n st.push(-1);\n int n = arr.size();\n\n for(int i=n-1; i>=0; i--) {\n\n int element = arr[i];\n\n \n while(st.top() != -1 && arr[...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<pair<int, int>> higher;\n vector<pair<int, int>> border;\n // higher stack: l -> r\n for (int i = 0; i < heights.size(); ++i) {\n int leftBorder;\n while (!higher.empty(...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> fbefore(vector<int> heights) {\n int n = heights.size();\n stack<pair<int, int>> s;\n s.push(make_pair(heights[0],0));\n vector<int> v(n);\n v[0] = -1;\n for (int i = 1; i < n; i++) {\n if (s.top().first < heigh...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> findNse(vector<int>& heights) {\n int n = heights.size();\n vector<int> ns(n, n);\n stack<pair<int,int>> st;\n\n for (int i = n - 1; i >= 0; i--) {\n while (!st.empty() && st.top().first > heights[i]) {\n st.po...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n=heights.size(), maxarea=0;\n stack<pair<int, int>> st1, st2;\n vector<int> nsl, nsr;\n for(int i=0; i<n; i++){\n if(st1.empty()) nsl.push_back(-1);\n if(!st1.empty() && ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n\n vector<int> nextsmaller(vector<int>& arr){\n int n = arr.size();\n stack<pair<int, int>> st;\n vector<int>ns;\n for(int i = n-1; i >= 0; i--){\n int curr = arr[i];\n while(!st.empty() && st.top().first >= curr){\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<pair<int,int>> st;\n vector<int> right;\n int n=heights.size();\n for(int i=n-1;i>=0;i--){\n \n while(!st.empty() && st.top().second>=heights[i]){\n st.pop();\n }\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n void nsr(vector<int>&heights,vector<int>&nsr_v){\n stack<pair<int,int>>stk;\n for(int i=heights.size()-1;i>=0;i--){\n while(!stk.empty() && stk.top().first >= heights[i]){\n stk.pop();\n }\n if(stk....
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\nvector<int>vr,vl;\nvoid rs(vector<int>& ar,int n){\n stack<int>st,in;\n for(int i=n-1;i>=0;i--){\n if(st.empty()){\n vr.push_back(n);\n }else{\n while(!st.empty()&&ar[i]<=st.top()){\n st.pop();\n in.pop();\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> leftsmall(vector<int> h) {\n stack<int> s;\n s.push(-1);\n vector<int> ans;\n for (int i = 0; i < h.size(); i++) {\n while (s.top() != -1 && h[i] <= h[s.top()]) {\n s.pop();\n }\n ans.push...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n vector<int> findPSE(vector<int> heights){\n vector<int> ans;\n stack<int> st;\n for(int i=0;i<heights.size();i++){\n while(!st.empty() && heights[st.top()]>=heights[i]){\n st.pop();\n }\n if(st.empty())\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\n private:\n\n vector<int>NSL(vector<int>&heights,int &n){\n stack<pair<int,int>>s;\n vector<int>li;\n for(int i=0;i<n;i++){\n int pi=-1;\n \n if(s.size()==0) li.push_back(pi);\n else if(s.size()>0 && s.top().first<heights[i]) li.push_back(s.top()...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n\nstruct Box {\n int h;\n int l;\n};\n int largestRectangleArea(vector<int>& heights) {\n int max_rect = 0;\n\n std::stack<Box> s;\n\n for (int i = 0; i < heights.size(); i++) {\n int curr_height = heights[i];\n if (s.empty()) {...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\n\n\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<int> left;\n vector<int> right;\n stack<int> q,q2;\n q.push(0);\n left.push_back(-1);\n for(int i=1;i<n;i++){\n while(!q.empty(...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\npublic:\nvector<int>vr,vl;\nvoid rs(vector<int>& ar,int n){\n stack<int>st,in;\n for(int i=n-1;i>=0;i--){\n if(st.empty()){\n vr.push_back(n);\n }else{\n while(!st.empty()&&ar[i]<=st.top()){\n st.pop();\n in.pop();\n ...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\nprivate:\n vector<int> nextSmallerElement(vector<int> arr, int n) {\n stack<int> s;\n s.push(-1);\n vector<int> ans(n);\n\n for(int i=n-1; i>=0 ; i--) {\n int curr = arr[i];\n while(s.top() != -1 && arr[s.top()] >= curr)\n {\...
84
<p>Given an array of integers <code>heights</code> representing the histogram&#39;s bar height where the width of each bar is <code>1</code>, return <em>the area of the largest rectangle in the histogram</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode...
3
{ "code": "class Solution {\nvoid print(vector<int> arr, int n){\n for(int i = 0; i<n; i++) cout<<arr[i]<<' ';\n cout<<endl;\n}\nvector<int> findNse(vector<int> heights, int n){\n vector<int> nse(n, -1);\n stack<int> st; // Monotonic stack stores elements in ascending order\n for(int i = n-1; i>=0; i--...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n const int m = matrix.size();\n const int n = matrix[0].size();\n int left[n], right[n], height[n];\n\n fill_n(left, n, 0);\n fill_n(right, n, n);\n fill_n(height, n, 0);\n\n ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n int res = 0;\n for (int r = 0; r < m; ++r) {\n for (int c = 0; c < n; ++c) {\n if (matrix[r][c] == '1') {\n ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int rows = matrix.size();\n int cols = matrix[0].size();\n int max = 0;\n vector<int> height(cols);\n vector<int> left(cols);\n vector<int> right(cols);\n int pos = 0;\n ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int findLargestAreaInHistogram(int n, vector<int>& rowHistogram) {\n int area = 0;\n for (int i = 0; i < n; i++) {\n int breadth = 1;\n // first find only this area\n area = max(area, rowHistogram[i] * breadth);\n // n...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int m=matrix.size();\n int n=matrix[0].size();\n int area=0;\n vector<int>h(n,0);\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n if(matrix[i][j]=='1'){h[j]+=...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int n = matrix.size();\n int m = matrix[0].size();\n vector<int> left(m, INT_MAX), right(m, INT_MAX), height(m, 0);\n int ans = 0;\n\n for (int i = 0; i < n; i++) {\n int curL...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n if(matrix.empty())return 0;\n int maxarea=0;\n int n=matrix.size(),m=matrix[0].size();\n vector<int> histogram(m+1,0);\n for(auto row:matrix){\n for(int i=0;i<m;i++){\n ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n if (matrix.empty()) return 0; // Edge case: empty matrix\n\n int n = matrix.size(); // Number of rows\n int c = matrix[0].size(); // Number of columns\n stack<int> stc;\n vector<int> ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n if(matrix.empty()){\n return 0;\n }\n int n = matrix.size();\n int c = matrix[0].size();\n stack<int>stc;\n vector<int>next_right(c,c);\n vector<int>next_left(c,...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int maxArea = 0;\n int rows = matrix.size();\n int cols = matrix[0].size();\n vector<int> heights(cols+1, 0);\n \n for(auto row : matrix) {\n for(int i = 0; i < cols; i...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "// Time: O(m * n)\n// Space: O(n)\n\n// Ascending stack solution.\nclass Solution {\npublic:\n int maximalRectangle(vector<vector<char> > &matrix) {\n if (matrix.empty() || matrix[0].empty()) {\n return 0;\n }\n\n int result = 0;\n vector<int> heights(matrix[0].si...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n if(matrix.empty() || matrix[0].empty()) {\n return 0;\n }\n \n int maxArea = 0;\n int rows = matrix.size();\n int cols = matrix[0].size();\n vector<int> heights(...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int n = matrix.size(), m = matrix[0].size(),i,j;\n vector<vector<int>> max_to_left(n, vector<int> (m,0));\n int curr = 0;\n for(i = 0; i < n ; i ++ ){\n\n max_to_left[i][0] = (matri...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& v) {\n int n = v.size(), m = v[0].size();\n vector<vector<int>> dp(n,vector<int>(m,0));\n for(int i=0;i<n;i++){\n int sum = 0;\n for(int j=0;j<m;j++){\n if(v[i][j] == '0')\n ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\nint solve(vector<int>& A){\n int ans=0;\n int n=A.size();\n for(int i=0;i<A.size();i++){\n int r=i+1,l=i-1;\n while(r<A.size()&&A[r]>=A[i]){\n r++;\n }\n while(l>=0&&A[l]>=A[i]){\n l--;\n }\n cout<<r<<' '<<l...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int h, w;\n vector<vector<int>> subsequentOnes;\n vector<vector<char>> m;\n\n void solveSubsequent() {\n for(int i = h - 1; i >= 0; i--) {\n for(int j = w - 1; j >= 0; j--) {\n if(m[i][j] == '0') subsequentOnes[i][j] = 0;\n ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n if (matrix.empty() || matrix[0].empty()) return 0;\n \n int n = matrix.size(), m = matrix[0].size();\n vector<int> now(m+1, 0);\n int ans = 0;\n\n for (auto row : matrix) {\n ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int m=matrix.size(),n=matrix[0].size();\n vector<int> curr(n+1);\n int mxarea=0;\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n curr[j]= matrix[i][j]=='1'?curr[j]+1...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int result = 0;\n vector<int> h(matrix[0].size(), 0);\n \n for (int i = 0 ; i < matrix.size() ; ++i) {\n stack<int> s;\n \n for (int j = 0 ; j < matrix[0].size(...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int result = 0;\n vector<int> h(matrix[0].size() + 1, 0);\n \n for (int i = 0 ; i < matrix.size() ; ++i) {\n stack<int> s;\n \n for (int j = 0 ; j < h.size(); +...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int n = matrix.size();\n int m = matrix[0].size();\n vector<int> heights(m + 1, 0);\n int ans = 0;\n for (auto row : matrix) {\n for (int i = 0; i < m; i++) {\n ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int n = matrix.size();\n int m = matrix[0].size();\n // for(auto u : matrix){\n // for(auto c : u ){\n // cout<<c<<\" \";\n // }\n // cout<<endl;\n ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n=heights.size();\n stack<int> st;\n int leftSmall[n],rightSmall[n];\n for(int i=0;i<n;i++){\n while(!st.empty() && heights[st.top()]>=heights[i]){\n st.pop();\n ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maxArea(vector<int>&v){\n stack<int>st;\n int ans = 0;\n int n = v.size();\n for(int i = 0; i<=n; i++){\n while(!st.empty() && (i == n || v[st.top()] >= v[i])){\n int height = v[st.top()];\n st.pop();\n ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maxArea(vector<int>&v){\n stack<int>st;\n int ans = 0;\n int n = v.size();\n for(int i = 0; i<=n; i++){\n while(!st.empty() && (i == n || v[st.top()] >= v[i])){\n int height = v[st.top()];\n st.pop();\n ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& height) {\n int maxA = 0;\n stack<int> st;\n for (int i = 0; i <= height.size(); i++) {\n while (!st.empty() &&\n (i == height.size() || height[st.top()] >= height[i])) {\n ...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
0
{ "code": "class Solution {\npublic:\n int maxInHistogram(vector<int>& arr) {\n int n = arr.size();\n int maxi = 0;\n stack<int> st;\n arr.push_back(0); \n for (int i = 0; i < arr.size(); ++i) {\n while (!st.empty() && arr[st.top()] >= arr[i]) {\n int h...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
1
{ "code": "class Solution {\npublic:\n int maxAreaInHistogram(vector<int> &heights)\\\n {\n int n = heights.size();\n stack<int> st;\n int maxArea = 0;\n for(int i=0;i<n;i++){\n while(!st.empty() && heights[i]<heights[st.top()]){\n int index = st.top();st.po...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
1
{ "code": "class Solution {\npublic:\n // Function to calculate the largest rectangle area in a histogram\nint largestRectangleArea(vector<int>& heights) {\n stack<int> st;\n int max_area = 0;\n int i = 0;\n\n while (i < heights.size()) {\n // Push current index to the stack if the stack is empt...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
1
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& A) {\n int M = A.size(), N = A[0].size(), ans = 0;\n vector<int> h(N), nextSmaller(N);\n for (int i = 0; i < M; ++i) {\n for (int j = 0; j < N; ++j) {\n h[j] = A[i][j] == '0' ? 0 : (h[j]...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
1
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& A) {\n int M = A.size(), N = A[0].size(), ans = 0;\n vector<int> h(N), nextSmaller(N);\n for (int i = 0; i < M; ++i) {\n for (int j = 0; j < N; ++j) {\n h[j] = A[i][j] == '0' ? 0 : (h[j]...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
1
{ "code": "#include <iostream>\n#include <vector>\n#include <stack>\n#include <algorithm>\nusing namespace std;\n\nclass Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) \n {\n stack<pair<int, int>> st; // Stack to store pairs of (height, index)\n int maxArea = 0;\n int...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
1
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& A) {\n int M = A.size(), N = A[0].size(), ans = 0;\n vector<int> h(N), nextSmaller(N);\n for (int i = 0; i < M; ++i) {\n for (int j = 0; j < N; ++j) {\n h[j] = A[i][j] == '0' ? 0 : (h[j]...
85
<p>Given a <code>rows x cols</code>&nbsp;binary <code>matrix</code> filled with <code>0</code>&#39;s and <code>1</code>&#39;s, find the largest rectangle containing only <code>1</code>&#39;s and return <em>its area</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://asse...
1
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& A) {\n int M = A.size(), N = A[0].size(), ans = 0;\n vector<int> h(N), nextSmaller(N);\n for (int i = 0; i < M; ++i) {\n for (int j = 0; j < N; ++j) {\n h[j] = A[i][j] == '0' ? 0 : (h[j]...