id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
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>>& matrix) {\n int m = matrix.size(), n = matrix[0].size();\n vector<int>leftmin(n, -1), height(n, 0);\n int ans = INT_MIN;\n for(int i=0;i<m;i++) {\n for(int j=0;j<n;j++) {\n height...
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 {\n int largestRectangleArea(vector<int>heights) {\n stack<int> st;\n int n = heights.size();\n int maxi = 0;\n for (int i = 0; i < n; i++) {\n while (!st.empty() && heights[st.top()] > heights[i]) {\n int curr = st.top();\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...
1
{ "code": "class Solution {\npublic:\n int histogram(vector<int> v){\n int n=v.size();\n stack<int> st;\n int ans=0;\n for(int i=0;i<n;i++){\n while(!st.empty() and v[st.top()]>v[i]){\n int ht=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...
1
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int res=INT_MIN;\n vector<vector<int>> mat(matrix.size(), vector<int>(matrix[0].size(), 0));\n int n=matrix.size(),m=matrix[0].size();\n for(int i=0;i<n;i++)\n { \n for(int j=0;j<m;j++)\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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& arr) {\n int n = arr.size();\n int prevsmaller[n];\n stack<int> st;\n\n for (int i = 0 ; i < n ; i++) {\n while(st.size()!=0 and arr[st.top()]>=arr[i])\n st.pop...
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 {\n int largestRectangleArea(vector<int>heights) {\n int n = heights.size();\n stack<int> st;\n int maxarea = 0, psc = -1, nsc = n;\n for (int i = 0; i < n; i++) {\n\n while (!st.empty() && heights[st.top()] > heights[i]) {\n int eleme...
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 {\n int largestRectangleArea(vector<int>heights) {\n int n = heights.size();\n stack<int> st;\n int maxarea = 0, psc = -1, nsc = n;\n for (int i = 0; i < n; i++) {\n\n while (!st.empty() && heights[st.top()] > heights[i]) {\n int eleme...
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<bits/stdc++.h>\nclass Solution {\npublic:\n\n int largesthist(vector<int> &A){\n stack<int> st;\n int maxarea=0;\n for(int i=0;i<A.size();i++){\n while(!st.empty() && A[st.top()]>A[i]){\n int ele= 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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& arr) {\n int n=arr.size();\n stack<int>st;\n int maxi=INT_MIN;\n int area=0;\n for(int i=0;i<n;i++){\n while(!st.empty() && arr[st.top()]>arr[i]){\n int x=st.top();\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...
2
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int m=matrix.size(),n=matrix[0].size();\n int rs=0;\n vector<int>dp(n,0);\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n if(matrix[i][j]=='0') dp[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...
2
{ "code": "class Solution {\npublic:\nint largestRectangleArea(vector<int>& heights) {\n int n=heights.size();\n stack<int>st;\n vector<int>right(n);\n int ans=0;\n int idx;\n for(int i=0;i<n;i++){\n while(!st.empty()&&heights[st.top()]>heights[i]){\n idx=st.to...
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...
2
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<int>right(n);\n stack<int>st;\n int max_area = 0;\n\n for(int i=0;i<n;i++){\n while(!st.empty() && heights[st.top()]>heights[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...
2
{ "code": "class Solution {\npublic:\nint largestRectangleArea(vector<int>& v) {\n stack<int> s1;\n stack<int> s2;\n int n = v.size();\n int left[n];\n int right[n];\n for (int i = 0; i < n; i++) {\n while (!s1.empty() && v[s1.top()] >= v[i])\n s1.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...
2
{ "code": "class Solution {\npublic:\nint largestRectangleArea(vector<int>& h) {\n stack<int> st;\n int ans = 0;\n int n=h.size();\n for(int i=0;i<n;i++){\n if(st.empty() || h[st.top()]<=h[i])\n st.push(i);\n else{\n int tp=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...
2
{ "code": "class Solution {\npublic:\nint largestRectangleArea(int heights[],int n) {\n int nse[n];\n int pse[n];\n stack<int>st_pse;\n stack<int>st_nse;\n for(int i=n-1;i>=0;--i){\n while(!st_nse.empty()&& heights[st_nse.top()]>=heights[i]){\n st_nse.pop()...
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...
2
{ "code": "class Solution {\npublic:\n int help(vector<int>v){\n\n int ans=0;\n stack<int>st;\n int n=v.size();\n for(int i=0;i<=v.size();i++){\n if(st.empty())\n st.push(i);\n else if(i!=n&&v[i]>v[st.top()]){\n st.push(i);\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...
2
{ "code": "class Solution {\npublic:\n int solve(vector<int> &hist) {\n stack<int> st;\n int i =0;\n int ans = 0;\n while (i<hist.size() ) {\n if (st.empty()|| hist[st.top()] <= hist[i]) {\n // if (st.empty()) {\n // ans = max(ans, hist[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...
2
{ "code": "class Solution {\npublic:\n int solve(vector<int> arr)\n {\n int maxi = 0;\n stack<int> st;\n\n for (int i = 0; i < arr.size(); i++)\n {\n while (!st.empty() && arr[st.top()] > arr[i])\n {\n int num = arr[st.top()];\n st....
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...
2
{ "code": "class Solution {\npublic:\n\n int solve(vector<int> arr)\n {\n int maxi=0;\n\n stack<int> st;\n \n\n for(int i=0;i<arr.size();i++)\n {\n while(!st.empty() && arr[st.top()]>arr[i])\n {\n int num=arr[st.top()];\n st....
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...
2
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int n = matrix[0].size();\n vector<int> heights(n);\n int ans = 0;\n for (auto& row : matrix) {\n for (int j = 0; j < n; ++j) {\n if (row[j] == '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...
2
{ "code": "class Solution {\npublic:\nint largestRectangleArea(vector<int>& nums) {\n int n = nums.size();\n vector<int> prevSmall(n, -1);\n vector<int> nextSmall(n, n);\n stack<int> st;\n for(int i = 0 ; i < n; i++){\n while(!st.empty() && nums[st.top()] > nums[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...
2
{ "code": "class Solution {\npublic:\n int largest(vector<int>& heights)\n {\n stack<pair<int, int>> stk;\n int res = 0;\n\n for (int i = 0; i < heights.size(); i++)\n {\n int start = i;\n\n while (!stk.empty() && stk.top().second > heights[i])\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...
2
{ "code": "#include <vector>\n#include <stack>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<int> st;\n int n = heights.size();\n vector<int> lsmall(n, -1);\n vector<int> rsmall(n, n); // rsmall shou...
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...
2
{ "code": "class Solution {\npublic:\n int solve(vector<int>&heights){\n int n=heights.size();\n stack<int>st;\n vector<int>next(n,-1);\n for(int i=0;i<heights.size();i++){\n while(st.empty()==false && heights[st.top()]>heights[i]){\n next[st.top()]=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...
2
{ "code": "class Solution {\npublic:\n int solve(vector<int>&heights){\n int n=heights.size();\n stack<int>st;\n vector<int>next(n,-1);\n for(int i=0;i<heights.size();i++){\n while(st.empty()==false && heights[st.top()]>heights[i]){\n next[st.top()]=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...
2
{ "code": "class Solution {\npublic:\n\tint n, m;\n\n /// from problem 84. Largest Rectangle in Histogram\n\tint largestRectangleArea(vector<int>& heights) {\n\t\tstack<int> st;\n\t\tint ans = 0;\n\t\theights.push_back(0);\n\t\tfor (int i = 0; i < heights.size(); i++) {\n\t\t\twhile (!st.empty() && heights[st.top(...
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...
2
{ "code": "class Solution {\npublic:\n void get_prevSmall(vector<int>& matrix, vector<int>& prevSmall){\n stack<int> st;\n st.push(-1);\n for(int i = 0; i < matrix.size(); i++){\n while(st.top() != -1 && matrix[st.top()] >= matrix[i]) st.pop();\n prevSmall[i] = st.top();\...
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...
2
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int m = matrix.size(), n = matrix[0].size();\n vector<int> vec(n, 0);\n int res = 0;\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n if (matrix[i][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...
2
{ "code": "class Solution {\npublic:\n\tint n, m;\n\tint largestRectangleArea(vector<int>& heights) {\n\t\tstack<int> st;\n\t\tint ans = 0;\n\t\theights.push_back(0);\n\t\tfor (int i = 0; i < heights.size(); i++) {\n\t\t\twhile (!st.empty() && heights[st.top()] > heights[i]) {\n\t\t\t\tint top = heights[st.top()];\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...
2
{ "code": "class Solution {\n vector<int> leftSmaller(vector<int> &arr)\n {\n int n = arr.size();\n stack<int> st;\n vector<int> ans;\n st.push(1);\n ans.push_back(0);\n for (int i = 1; i < n; i++) {\n while (!st.empty() && arr[i] <= arr[st.top()-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...
2
{ "code": "class Solution {\npublic:\n\n vector<vector<int>> dp;\n\nint f(int ind) {\n int m = dp[0].size();\n vector<int> pf(m, 0); // Distance to the left bound (inclusive)\n vector<int> sf(m, 0); // Distance to the right bound (inclusive)\n stack<int> st;\n\n // Calculate prefix (pf) - distance ...
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...
2
{ "code": "class Solution {\npublic:\n int calculateMaxArea(vector<int> arr, int n) {\n int area = 0;\n vector<int> minleft(n), minright(n);\n stack<int> st;\n for (int i = 0; i < n; i++) {\n while (!st.empty() && arr[st.top()] >= arr[i]) {\n minright[st.top()]...
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...
2
{ "code": "class Solution {\npublic:\n\n int largestRectangleArea(vector<int>& heights) {\n int n=heights.size();\n if(n==1) return heights[0];\n vector<int> ps(n),ns(n);\n stack<int> s,s1;\n for(int i=0;i<heights.size();i++){\n while(!s.empty() && heights[s.top()]>=he...
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...
2
{ "code": "class Solution {\npublic:\n \n int maxArea(vector<int> &nums) {\n int n = nums.size();\n // for(int i=0;i<n;i++) cout << nums[i] << \" \";\n // cout << endl;\n vector<int> left(n, -1);\n vector<int> right(n, -1);\n \n stack<int> st;\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...
2
{ "code": "class Solution {\npublic:\n int func(vector<int> &v){\n int n=v.size();\n stack<int> st;\n vector<int> l(n),r(n);\n for(int i=0;i<n;i++){\n while(!st.empty() && v[st.top()]>=v[i]) st.pop();\n l[i]=(st.empty()?i+1:i-st.top());\n st.push(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...
2
{ "code": "class Solution {\npublic:\n int func(vector<int> &v){\n int n=v.size();\n stack<int> st;\n vector<int> l(n),r(n);\n for(int i=0;i<n;i++){\n while(!st.empty() && v[st.top()]>=v[i]) st.pop();\n l[i]=(st.empty()?i+1:i-st.top());\n st.push(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...
2
{ "code": "class Solution {\npublic:\nint largestRectangleArea(vector<int>& hights) {\n int n = hights.size(), ans = 0;\n// monotonic stack\n vector<int>left(n , 0), right(n , 0);\n stack<int>st;\n st.push(-1);\n for(int i = 0 ; i < n ; i++){\n int id = st.top();\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...
2
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n int n = (int)matrix.size();\n int m = (int)matrix[0].size();\n\n auto getArea = [&](vector<int> A)->int {\n int n = (int)A.size();\n vector<int> left(n), right(n);\n s...
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...
2
{ "code": "class Solution {\n private:\n vector<int> nextSmaller(vector<int>& arr, 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 int curr = arr[i];\n while (s.top() != -1 && arr[s.top()] >= curr) {\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...
3
{ "code": "class Solution {\npublic:\nvector<int> NSL(vector<int>&arr){\n int n= arr.size();\n vector<int>ans(n,-1);\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 ans[i]=st.top();\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...
3
{ "code": "class Solution {\n vector<int> nextSmallIndex(vector<int>&arr)\n {\n stack<int>st;\n int n = arr.size();\n vector<int>ans(n);\n\n for(int i=n-1;i>=0;i--)\n {\n while(!st.empty() && arr[st.top()] >= arr[i])\n {\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...
3
{ "code": "class Solution {\npublic:\n\n int ans=0;\n void find(vector<int> v,int n)\n {\n vector<int> left(n,-1);\n vector<int> right(n,n);\n stack<int> st;\n st.push(0);\n for(int i=1;i<n;i++)\n {\n while(!st.empty() && v[st.top()]>=v[i])\n {\n st.pop(...
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...
3
{ "code": "class Solution {\npublic:\n int hist(vector<int>v,int n){\n vector<int>pse(n,-1),nse(n,n);\n stack<int>st;\n int prod=0,maxProd=0;\n for(int i=0; i<n; i++){\n while(!st.empty() && v[st.top()] >= v[i]){\n st.pop();\n }\n if(!st.e...
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...
3
{ "code": "using ll = long long;\nclass Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n ll n = matrix.size(),m = matrix[0].size();\n\n auto a = matrix;\n for(auto x:a) { for(auto ch:x) cout << ch<<' '; cout <<endl;}\n vector<vector<int>> pos(n,vector<int>(m,...
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...
3
{ "code": "class Solution {\npublic:\n int calculateMaxArea(vector<int> arr, int n) {\n int area = 0;\n vector<int> minleft(n), minright(n);\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 ...
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...
3
{ "code": "class Solution {\npublic:\n int calculateMaxArea(vector<int> arr, int n) {\n int area = 0;\n // find nearest smaller to right and left and find area\n vector<int> minleft, minright;\n minleft.reserve(n);\n minright.reserve(n);\n stack<int> st;\n // min le...
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...
3
{ "code": "class Solution {\npublic:\n int solve(vector<int> &dp){\n int n = dp.size();\n stack<int> nse;\n stack<int> pse;\n\n vector<int> l(n, -1);\n vector<int> r(n, n);\n\n for(int i=0;i<n;i++){\n while(!pse.empty() && dp[pse.top()]>=dp[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...
3
{ "code": "class Solution {\npublic:\n vector<int> nextSmaller(vector<int> &arr){\n stack<int> s;\n s.push(-1);\n int n = arr.size();\n vector<int> ans(n);\n for(int i=n-1; i>=0; i--){\n int item = arr[i];\n while(s.top() != -1 && arr[s.top()] >= item)\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...
3
{ "code": "class Solution {\nprivate:\n vector<int> nextsmallerelements(vector<int> &temp){\n vector<int> ans(temp.size());\n stack<int> s;\n for(int i=temp.size()-1;i>=0;i--){\n while(!s.empty() && temp[s.top()]>=temp[i]){\n s.pop();\n }\n if(!s...
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...
3
{ "code": "class Solution {\npublic:\n vector<int> findNSE(vector<int>& nums) {\n int n = nums.size();\n vector<int> nse(n);\n stack<int> st;\n for (int i = n - 1; i >= 0; i--) {\n while (!st.empty() && nums[st.top()] >= nums[i])\n st.pop();\n nse[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...
3
{ "code": "class Solution {\npublic:\n vector<int> presin(vector<int>& heights)\n {\n stack<int> st;\n int n = heights.size();\n vector<int> pse(n);\n for(int i = 0; i < n; i++)\n {\n while(!st.empty() && heights[i] <= heights[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...
3
{ "code": "int desperate_optimization(int precision){\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n cout.setf(ios::fixed);\n cout.setf(ios::showpoint);\n cout.precision(precision);\n return 0;\n}\n\nclass Solution {\npublic:\n\n vector<int> PSE(vector<int> & nums){\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...
3
{ "code": "class Solution {\npublic:\n vector<int>nextSmaller(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 s.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...
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 ...
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...
3
{ "code": "class Solution {\npublic:\n vector<int> nexts(vector<int>& heights){\n int n = heights.size();\n vector<int> ans(n);\n stack<int> st;\n st.push(-1);\n for(int i=n-1; i>=0; i--){\n while(st.top()!=-1 && heights[st.top()]>=heights[i]){\n st.pop(...
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...
3
{ "code": "class Solution {\n private:\n vector<int>nextSmaller(vector<int>arr){\n int n=arr.size();\n stack<int>st;\n vector<int>nse(n);\n for(int i=n-1;i>=0;i--){\n while(!st.empty()&&arr[st.top()]>arr[i])st.pop();\n if(st.empty())nse[i]=n;\n else{\...
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...
3
{ "code": "class Solution {\npublic:\n\n vector<int> nextsmallerelement(vector<int>& input){\n\n stack<int> s;\n s.push(-1);\n\n vector<int> ans(input.size());\n\n for(int i = input.size()-1 ; i>=0 ; i--){\n\n int x = input[i];\n\n while(s.top() !=-1 && input[s.top()] >= x){\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...
3
{ "code": "class Solution {\npublic:\nvector<int> getNSR(vector<int>& height){\n int n=height.size();\n vector<int> NSR(n);\n stack<int>st;\n for(int i=n-1; i>=0; i--){\n if(st.empty()) NSR[i]=n;\n\n else{\n while(!st.empty() && height[st.top()]>=height[i]){\n 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...
3
{ "code": "class Solution {\n \n\n vector<int>rightSmallerElement(vector<int>&arr)\n {\n \n int n=arr.size();\n vector<int>ans(n);\n stack<int>stk;\n for(int i=n-1;i>=0;i--)\n {\n while(!stk.empty())\n {\n if(arr[stk.top()]<arr[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...
3
{ "code": "class Solution {\npublic:\n //next smaller element\n vector<int> findNSE(vector<int> &arr)\n {\n int n=arr.size();\n stack<int>st;\n vector<int>nse(n,-1);\n for(int i=n-1;i>=0;i--)\n {\n while(!st.empty() && arr[st.top()]>=arr[i])\n st.p...
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...
3
{ "code": "class Solution {\npublic:\n int max_rectangle(vector<int> arr){\n int maxi = 0;\n arr.push_back(0);\n stack<int> stk;\n int i=0,n=arr.size();\n while(i<n){\n while(!stk.empty() && arr[stk.top()]>arr[i]){\n int temp = stk.top();\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...
3
{ "code": "class Solution {\n\nvector<int> nextSmallerElement(vector<int> arr, int n){\n vector<int> ansArr(n, n);\n stack<int> st;\n\n for(int i=n-1; i>=0; i--){\n while(!st.empty() && arr[st.top()] >= arr[i]) st.pop();\n if(!st.empty()) ansArr[i] = st.top();\n st.push(i);\n }\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...
3
{ "code": "class Solution {\npublic:\nint solve(vector<int>& heights){\n heights.insert(heights.begin(),-1);\n heights.push_back(-1);\n int n = heights.size();\n vector<int> nse(n);\n vector<int> pse(n);\n\n stack<int> st;\n st.push(0);\n for(int i=1; i<n-1; 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...
3
{ "code": "class Solution {\npublic:\nint solve(vector<int>& heights){\n heights.insert(heights.begin(),-1);\n heights.push_back(-1);\n int n = heights.size();\n vector<int> nse(n);\n vector<int> pse(n);\n\n stack<int> st;\n st.push(0);\n for(int i=1; i<n-1; 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...
3
{ "code": "class Solution {\npublic:\nint solve(vector<int>& heights){\n heights.insert(heights.begin(),-1);\n heights.push_back(-1);\n int n = heights.size();\n vector<int> nse(n);\n vector<int> pse(n);\n\n stack<int> st;\n st.push(0);\n for(int i=1; i<n-1; 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...
3
{ "code": "class Solution {\npublic:\nint solve(vector<int>& heights){\n heights.insert(heights.begin(),-1);\n heights.push_back(-1);\n int n = heights.size();\n vector<int> nse(n);\n vector<int> pse(n);\n\n stack<int> st;\n st.push(0);\n for(int i=1; i<n-1; 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...
3
{ "code": "using namespace std;\n\nclass Solution {\nprivate:\n vector<int> nextsmallele(vector<int> arr, int n) {\n stack<int> st;\n vector<int> ans(n);\n st.push(-1);\n for (int i = n - 1; i >= 0; i--) {\n int curr = arr[i];\n while ((st.top() != -1) && (arr[st.t...
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...
3
{ "code": "class Solution {\nprivate:\n vector<int> nextSmallest(vector<int> row){\n stack<int> st;\n st.push(-1);\n int n = row.size();\n vector<int> soln(n);\n for(int i = n-1; i >= 0; i--){\n int elem = row[i];\n while(st.top() != -1 && row[st.top()] >= e...
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...
3
{ "code": "class Solution {\nprivate:\n vector<int> nextSmallerElementIndex(int* arr,int n){\n stack<int> st;\n st.push(-1);\n vector<int> ans(n);\n \n for(int i=n-1;i>=0;i--){\n if(st.top()!=-1 && arr[st.top()]<arr[i]){\n ans[i]=st.top();\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...
3
{ "code": "class Solution {\npublic:\n vector<int> leftmin(vector<int> arr){\n int n = arr.size();\n stack<int> st;\n vector<int> ans(n,0);\n for(int i = n-1; i>=0; i--){\n while(!st.empty() && arr[st.top()]>arr[i]){\n ans[st.top()]=i;\n st.pop()...
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...
3
{ "code": "class Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n \n if(matrix.empty()) return 0;\n int m=matrix.size();\n int n=matrix[0].size();\n vector<int> temp(n,0);\n int area=0;\n for(int i=0; i<m; i++){\n for(int j=0; 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...
3
{ "code": "class Solution {\npublic:\nvector<int> rs(vector<int>& ar){\n stack<int>st;\n vector<int>vr;\n int l=ar.size();\n for(int i=l-1;i>=0;i--){\n while(!st.empty()&&ar[st.top()]>=ar[i]){\n st.pop();\n }\n if(st.empty()){\n vr.push_back(l);\n }else{\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...
3
{ "code": "class Solution {\npublic:\n\n vector<int> nextsmallerelement(vector<int> input){\n\n stack<int> s;\n s.push(-1);\n\n vector<int> ans(input.size());\n\n for(int i = input.size()-1 ; i>=0 ; i--){\n\n int x = input[i];\n\n while(s.top() !=-1 && input[s.top()] >= x){\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...
3
{ "code": "class Solution {\nprivate:\n // Function to find the index of the previous smaller element for each element in 'row'\n vector<int> presmaller(vector<int> &row) {\n int n = row.size();\n vector<int> ans;\n stack<int> s;\n s.push(-1);\n for (int i = 0; i < n; 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...
3
{ "code": "class Solution {\npublic:\n vector<int> findNSE(vector<int>& nums) {\n int n = nums.size();\n vector<int> nse(n);\n stack<int> st;\n for (int i = n - 1; i >= 0; i--) {\n while (!st.empty() && nums[st.top()] >= nums[i])\n st.pop();\n nse[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...
3
{ "code": "class Solution {\n vector<int> presmaller(vector<int> &row) {\n int n = row.size();\n vector<int> ans;\n stack<int> s;\n s.push(-1);\n for (int i = 0; i < n; i++) {\n while (s.size() > 1 && row[s.top()] >= row[i]) {\n s.pop();\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...
3
{ "code": "class Solution {\npublic:\n\n vector<int> nextSmallerElement(vector<int> arr,int n){\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\n while(s.top() != -1 && arr[s.top()] >= curr){\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...
3
{ "code": "class Solution {\npublic:\n vector<int> findNSE(vector<int>& nums) {\n int n = nums.size();\n vector<int> nse(n);\n stack<int> st;\n for (int i = n - 1; i >= 0; i--) {\n while (!st.empty() && nums[st.top()] >= nums[i])\n st.pop();\n nse[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...
3
{ "code": "class Solution {\npublic:\n vector<int> findNSE(vector<int>& nums) {\n int n = nums.size();\n vector<int> nse(n);\n stack<int> st;\n for (int i = n - 1; i >= 0; i--) {\n while (!st.empty() && nums[st.top()] >= nums[i])\n st.pop();\n nse[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...
3
{ "code": "class Solution {\n private:\n vector<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()...
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...
3
{ "code": "class Solution {\npublic:\n\n vector<int>prevSmaller(vector<int>&input){\n stack<int> st;\n st.push(-1);\n\n vector<int> ans(input.size()); \n \n\n for (int i = 0; i < input.size(); i++) {\n int curr = input[i];\n\n while ( st.top()!= -1 && input[st.top()] >= curr) ...
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...
3
{ "code": "class Solution {\npublic:\n vector<int> solve1(vector<int>& heights){\n stack<int>s;\n s.push(-1);\n vector<int>next(heights.size());\n for(int i=heights.size()-1;i>=0;i--){\n while(s.top()!=-1 && heights[s.top()]>=heights[i]){\n s.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...
3
{ "code": "class Solution {\npublic:\n vector<int> pse(vector<int> arr){\n int n=arr.size();\n stack<int> st;\n vector<int> v;\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 ...
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...
3
{ "code": "class Solution {\n private:\n int solve(vector<int>&heights){\n stack<int>st,st1;\n int n=heights.size();\n vector<int>pre,suff;\n for(int i=n-1;i>=0;i--){\n while(!st.empty() && heights[st.top()]>=heights[i]){\n st.pop();\n }\n if(st.empty()){\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...
3
{ "code": "class Solution {\npublic:\nvector<int>v;\nint MAH(vector<int> &v){\n \nvector<int> right;\nvector<int> left;\nstack<pair<int,int>> s;\n// Step 1: Calculate 'right' array (nearest smaller element to the right)\n for(int j = v.size() - 1; j>= 0; j--) {\n while (!s.empty() && s.top().firs...
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...
3
{ "code": "class Solution {\npublic:\n vector<int> nsr(vector<int>& arr){\n int n=arr.size();\n vector<int> right;\n stack<pair<int,int>> s;\n \n for(int i=n-1;i>=0;i--){\n \n if(s.size()==0){\n right.push_back(n);\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...
3
{ "code": "class Solution {\npublic:\n vector<int> nextSmallerElement(vector<int> arr, int n) {\n stack<int> s;\n s.push(-1);\n vector<int> ans(n, 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 ...
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...
3
{ "code": "class Solution {\npublic:\nvector<int> nextsmall(vector<int> v, int n){\n\n stack<int> s;\n s.push(-1);\n vector<int>ans(n);\n\n for(int j=n-1;j>=0;j--){\n //int num=v[j];\n while(s.top() != -1 && v[s.top()] >= v[j]){\n s.pop();\n }\n\n ans[j]=s.top();\n ...
86
<p>Given the <code>head</code> of a linked list and a value <code>x</code>, partition it such that all nodes <strong>less than</strong> <code>x</code> come before nodes <strong>greater than or equal</strong> to <code>x</code>.</p> <p>You should <strong>preserve</strong> the original relative order of the nodes in each...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
86
<p>Given the <code>head</code> of a linked list and a value <code>x</code>, partition it such that all nodes <strong>less than</strong> <code>x</code> come before nodes <strong>greater than or equal</strong> to <code>x</code>.</p> <p>You should <strong>preserve</strong> the original relative order of the nodes in each...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
86
<p>Given the <code>head</code> of a linked list and a value <code>x</code>, partition it such that all nodes <strong>less than</strong> <code>x</code> come before nodes <strong>greater than or equal</strong> to <code>x</code>.</p> <p>You should <strong>preserve</strong> the original relative order of the nodes in each...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
86
<p>Given the <code>head</code> of a linked list and a value <code>x</code>, partition it such that all nodes <strong>less than</strong> <code>x</code> come before nodes <strong>greater than or equal</strong> to <code>x</code>.</p> <p>You should <strong>preserve</strong> the original relative order of the nodes in each...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
86
<p>Given the <code>head</code> of a linked list and a value <code>x</code>, partition it such that all nodes <strong>less than</strong> <code>x</code> come before nodes <strong>greater than or equal</strong> to <code>x</code>.</p> <p>You should <strong>preserve</strong> the original relative order of the nodes in each...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
86
<p>Given the <code>head</code> of a linked list and a value <code>x</code>, partition it such that all nodes <strong>less than</strong> <code>x</code> come before nodes <strong>greater than or equal</strong> to <code>x</code>.</p> <p>You should <strong>preserve</strong> the original relative order of the nodes in each...
0
{ "code": "class Solution {\npublic:\n ListNode* partition(ListNode* head, int x) {\n ListNode* d1 = new ListNode();\n ListNode* d2 = new ListNode();\n ListNode* t1 = d1;\n ListNode* t2 = d2;\n while (head) {\n if (head->val < x) {\n t1->next = head;\n ...
86
<p>Given the <code>head</code> of a linked list and a value <code>x</code>, partition it such that all nodes <strong>less than</strong> <code>x</code> come before nodes <strong>greater than or equal</strong> to <code>x</code>.</p> <p>You should <strong>preserve</strong> the original relative order of the nodes in each...
0
{ "code": "class Solution {\npublic:\n ListNode* partition(ListNode* head, int x) {\n ListNode* d1 = new ListNode();\n ListNode* d2 = new ListNode();\n ListNode* t1 = d1;\n ListNode* t2 = d2;\n while (head) {\n if (head->val < x) {\n t1->next = head;\n ...
86
<p>Given the <code>head</code> of a linked list and a value <code>x</code>, partition it such that all nodes <strong>less than</strong> <code>x</code> come before nodes <strong>greater than or equal</strong> to <code>x</code>.</p> <p>You should <strong>preserve</strong> the original relative order of the nodes in each...
0
{ "code": "class Solution {\npublic:\n ListNode* partition(ListNode* head, int x) {\n ListNode* dummy1 = new ListNode();\n ListNode* temp1 = dummy1;\n ListNode* dummy2 = new ListNode();\n ListNode* temp2 = dummy2;\n while (head != NULL) {\n if (head->val < x) {\n ...
86
<p>Given the <code>head</code> of a linked list and a value <code>x</code>, partition it such that all nodes <strong>less than</strong> <code>x</code> come before nodes <strong>greater than or equal</strong> to <code>x</code>.</p> <p>You should <strong>preserve</strong> the original relative order of the nodes in each...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
86
<p>Given the <code>head</code> of a linked list and a value <code>x</code>, partition it such that all nodes <strong>less than</strong> <code>x</code> come before nodes <strong>greater than or equal</strong> to <code>x</code>.</p> <p>You should <strong>preserve</strong> the original relative order of the nodes in each...
2
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
86
<p>Given the <code>head</code> of a linked list and a value <code>x</code>, partition it such that all nodes <strong>less than</strong> <code>x</code> come before nodes <strong>greater than or equal</strong> to <code>x</code>.</p> <p>You should <strong>preserve</strong> the original relative order of the nodes in each...
2
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...