id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
3
{ "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...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
3
{ "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...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
3
{ "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...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
3
{ "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...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
3
{ "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...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
3
{ "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...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
3
{ "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...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
3
{ "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...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
3
{ "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...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
3
{ "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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
0
{ "code": "class Solution {\npublic:\n ListNode* deleteDuplicates(ListNode* head) {\n ListNode* ptr = head;\n \n while (ptr != nullptr) {\n while (ptr->next != nullptr && ptr->val == ptr->next->val) {\n ptr->next = ptr->next->next;\n }\n ptr = pt...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
1
{ "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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
1
{ "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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
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...
83
<p>Given the <code>head</code> of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/202...
2
{ "code": "class Solution {\npublic:\n ListNode* deleteDuplicates(ListNode* head) {\n if (head == NULL) {\n return head;\n }\n \n ListNode* curr = head;\n\n while (curr != NULL && curr->next != NULL) {\n if (curr->val == curr->next->val) {\n L...
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...
0
{ "code": " class Solution {\n public:\n int largestRectangleArea(vector<int> &height) {\n \n int ret = 0;\n height.push_back(0);\n vector<int> index;\n \n for(int i = 0; i < height.size(); i++)\n {\n while(index.si...
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...
0
{ "code": " class Solution {\n public:\n int largestRectangleArea(vector<int> &height) {\n \n int ret = 0;\n height.push_back(0);\n vector<int> index;\n \n for(int i = 0; i < height.size(); i++)\n {\n while(index.si...
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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int largest = 0;\n vector<pair<int, int>> mins;\n for (int i = 0; i < heights.size(); ++i)\n {\n while (!mins.empty() && mins.back().first >= heights[i])\n mins.pop_back()...
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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<pair<int, int>> vec;\n //<tall, idx>\n //only check when it pop\n // and the last vec\n int res = 0;\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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& hgt) {\n int mx = 0 ; \n stack<int>st;\n st.push(-1);\n int ans =0 ; \n for(int i =0 ; i < hgt.size() ; i++)\n { \n int num = hgt[i];\n \n while( st.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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n\n stack<int> height;height.push(-1);\n int max_area = 0;\n \n int a = 0;\n int b = 0;\n\n for( int i = 0 ; i < n ; i ++ )\n {\n while...
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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<int> stack;\n stack.push(-1);\n int max_area = 0;\n\n for (int i = 0; i < heights.size(); i++) {\n while (stack.top() != -1 && heights[i] <= heights[stack.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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int res=0;\n stack<int> st;\n int n =heights.size();\n for(int i=0;i<n;i++){\n while(!st.empty() && heights[st.top()]>=heights[i])\n {\n int idx = 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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& h) {\n vector<pair<int, int> > s;\n int n = h.size();\n int l[n],r[n];\n for(int i=n-1;i>-1;i--) {\n int count = 0;\n while(!s.empty() && s[s.size()-1].first>=h[i]) {\n coun...
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...
0
{ "code": "class Solution {\npublic:\n int merge(int st,int md,int end,vector<int>& heights){\n int mx=-1;\n int a=md,b=md,mn=heights[md],f=a,e=b;\n while (a>=st && b<=end){\n if(heights[a]>heights[b]){ \n mn=min(mn,heights[a]);\n f=a;\n a--;\n }\n else if(h...
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...
0
{ "code": "class Solution {\npublic:\n#define pii pair<int, int>\n int largestRectangleArea(vector<int>& h) {\n int n = h.size();\n int res = 0;\n stack<pii> st;\n for (int i = 0; i < n; i++) {\n int idx = i;\n while (!st.empty() && h[i] <= st.top().second) {\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...
0
{ "code": "// O(N) runtime and O(N) space\n// implement stack\n// iterate through and keep track of start index\n// create another while loop w/ the given case that the top val in stack in greater than heights[i], (keep it monotonically increasing)\n// in second loop calculate max area for the top value on stack\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...
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 ...
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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& height) {\n int n = height.size();\n stack<int>st;\n int leftsmall[n],rightsmall[n];\n\n for(int i=0; i < n; i++){\n while(!st.empty() && 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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& height) {\n int n=height.size();\n int pse[n]; //previous smaller element;\n int nse[n]; //nextsmaller element\n stack<int>st;\n for(int i=0;i<n;i++){\n while(!st.empty() and height[st.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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& arr) {\n int n = arr.size();\n stack<int>st;\n int nsi[n];\n nsi[n-1] = n;\n st.push(n-1);\n for(int i = n-2 ; i>=0 ; i-- ){\n while(st.size()>0 && arr[st.top()]>=arr[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...
0
{ "code": "\n#include <iostream>\n#include <utility>\n#include <vector>\n\nclass Solution {\nprivate:\n struct Record { int height_; std::size_t index_; };\npublic:\n int largestRectangleArea(std::vector<int>& heights) {\n if (heights.empty()) {\n return 0;\n }\n std::vector<Reco...
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...
0
{ "code": "class Stack{\n private:\n int* data;\n int top;\n int MAXsize;\n\n public:\n Stack(int size){\n top = -1;\n MAXsize = size;\n data = new int[size];\n };\n\n bool IsEmpty(){\n return (top == -1);\n };\n\n int get_top(){\n return data[top];\n };\n\n bo...
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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n=heights.size(), ans=0;\n stack<int> st; //stores indices\n\n for(int i=0; i<n; i++){\n while(!st.empty() && heights[i]<heights[st.top()]){\n int topIdx=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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector < int > & histo) {\n stack < int > st;\n int maxA = 0;\n int n = histo.size();\n for (int i = 0; i <= n; i++) {\n while (!st.empty() && (i == n || histo[st.top()] > histo[i])) {\n int height = histo[st.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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int ans = 0;\n heights.push_back(0);\n stack<int> index;\n index.push(0);\n for(auto i=0;i<heights.size();i++){\n\n while(!index.empty() and heights[index.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...
0
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n stack<int> st; // Stack to store indices\n int max_area = 0;\n int i = 0;\n \n while (i < n) {\n // If the stack is empty or the current height is greater than the 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...
1
{ "code": "class Solution {\npublic:\n // vector<int> NSR(vector<int>& heights){\n // int n = heights.size();\n // vector<int> nsr(n);\n // stack<int> st;\n // for(int i=0;i<n;i++){\n // while(!st.empty() && heights[i]<heights[st.top()]){\n // nsr[st.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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<int> st;\n int maxi=0;\n for(int i=0;i<heights.size();i++){\n while(!st.empty() && heights[st.top()]>heights[i]){\n int ele= 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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int ans = 0;\n int n = heights.size();\n\n // increasing stack\n vector<int> s(n, 0);\n int r = 0;\n\n int cur, left;\n for (int i = 0; i < n; i++){\n while(r > 0 &&...
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...
1
{ "code": "class Solution {\npublic:\nunsigned long long maximum(unsigned long long a, unsigned long long b)\n {\n if(a>b)return a;\n else return b;\n }\n int largestRectangleArea(vector<int>& arr) {\n int n=arr.size();\n long long left[n],right[n]; //will note the index o...
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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n // vector<int>& a = heights;\n // int n = heights.size();\n // int NSN[n], PSN[n];\n // fill(NSN, NSN + n, n);\n // fill(PSN, PSN + n, -1);\n // // vector<int> NSN(n,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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& v) {\n v.push_back(0); // inserting 0 at end as at the end of loop it\n // will calculate max area for all remaining data in stack. \n int n = v.size();\n vector<int>st;\n vector<int>dp(n,0); // stores ...
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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<int>& a = heights;\n\n int pse[n], nse[n];\n fill(pse, pse + n, -1);\n fill(nse, nse + n, n);\n\n stack<int> s;\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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n if(n==1){\n return heights[0];\n }\n int nse[n],pse[n];\n stack<int>st;\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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) \n {\n stack<int> st;\n\n int n=heights.size();\n\n vector<int> v(n);\n\n for(int i=n-1;i>=0;i--)\n {\n while(!st.empty() && heights[st.top()] >= heights[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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& a) {\n stack<int>s;\n vector<int>pre(a.size());\n for(int i=0;i<a.size();i++){\n while(!s.empty()&&a[s.top()]>=a[i]){\n s.pop();\n }\n if(s.empty()){\n pr...
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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<int> min_track;\n int res = 0;\n vector<int> reach (heights.size(), 1);\n for (int i=0; i < heights.size(); i++) {\n if (min_track.empty()){\n min_track.push(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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n int maxi = 0;\n stack<int>st;\n vector<int>prevMin(n, -1);\n for(int i=0; i<n; i++)\n {\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...
1
{ "code": "class Solution {\npublic:\n vector<int> NSE(vector<int>& heights){\n int n = heights.size();\n vector<int> nse(n);\n stack<int> stk;\n for(int i = n-1; i>=0; i--){\n while(!stk.empty() && heights[stk.top()] >= heights[i]) stk.pop();\n nse[i] = stk.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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<pair<int, int>> st;\n vector<int> pse(heights.size(), 0 );\n int ans = 0;\n for(int i = 0; i < heights.size() ; i ++){\n //if element is smaller than top pop the top and calculate ...
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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n int mA = 0;\n vector<int> dp1(n,0);\n stack<pair<int,int>> s;\n s.push({-1,-1});\n for(int i=0;i<n;i++){\n while(s.top().first >= heights[i]) 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...
1
{ "code": "#define fst(t) (get<0>(t))\n#define snd(t) (get<1>(t))\nusing pii = tuple<int,int>;\n\nclass Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<pii> s;\n vector<int> ans = heights;\n\n for(int i=0; i<heights.size(); i++) {\n while(!s.empty() an...
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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<int> left(n);\n int maxArea = 0;\n stack<pair<int,int>> s,s1;\n for (int i = 0; i < n; i++) {\n while (!s.empty() && s.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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<int> left(n);\n int maxArea = 0;\n stack<pair<int,int>> s,s1;\n for (int i = 0; i < n; i++) {\n while (!s.empty() && s.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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n heights.push_back(0);\n stack<pair<int, int>> s;\n int maxArea = 0;\n for (int i = 0; i < heights.size(); ++i) {\n int start = i;\n while (!s.empty() && s.top().second > 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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<int> left;\n stack<int> right;\n\n int sizes[heights.size()];\n\n int maxArea = 0;\n\n for (int i = 0; i < heights.size(); ++i) {\n while (!left.empty() && heights[left.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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int maxArea = 0;\n // Stack will store pairs of (index, height) for the histogram bars\n // This will be a monotonic stack, meaning the heights in the stack are \n // in increasing order from botto...
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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<pair<int,int>> stk;\n int ans = 0;\n int start = 0;\n for(int i = 0; i < heights.size(); i++){\n start = i;\n while(!stk.empty() && stk.top().first > 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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& h) {\n stack<pair<int,int>> st1;\n stack<pair<int,int>> st2;\n int n = h.size();\n\n int res = -1;\n for (int i=0; i<h.size(); ++i) {\n int index = i;\n while(!st1.empty() && st1.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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<int> pse(n, -1);\n stack<int> s;\n int ans = 0;\n for(int i=0; i<n; i++){\n int pse = -1, nse = n;\n bool flag = false;\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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int ans=0;\n int n = heights.size();\n stack<int> st;\n vector<int> pse(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...
1
{ "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 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=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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int maxA = 0; \n int H = heights.size(); \n\n vector<int> leftArr (H, 0); \n vector<int> rightArr (H, 0); \n\n int idx; \n for (int i = 1; i < H; i++) {\n idx = i - 1; \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...
1
{ "code": "class Solution {\npublic:\n\n int largestRectangleArea(vector<int>& heights) {\n heights.insert(heights.begin(),-1);\n heights.push_back(-1);\n int n = heights.size();\n\n vector<int> next(n),prev(n);\n\n prev[0] = 0;\n for(int i = 1;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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<int> psm(n); // Previous smaller element index\n vector<int> nsm(n); // Next smaller element index\n \n // Compute psm (Previous Smaller Element)\n fo...
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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<int> nextSmaller(n), prevSmaller(n);\n vector<int> queue;\n for (int i = n - 1; i >= 0; i--) {\n\n while (queue.size() && heights[queue.back()] >= 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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<int> prevSmaller(n), nextSmaller(n);\n vector<int> prevSt, nextSt;\n prevSt.push_back(-1);\n nextSt.push_back(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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<int> Stack1, Stack2;\n if(heights.size()<2)\n return heights[0];\n vector<pair<int,int>> vec;\n vec.resize(heights.size());\n int index = 0;\n \n for(auto itr:...
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...
1
{ "code": "class Solution {\n public:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size(), maximum = 0;\n stack<int> sta;\n vector<pair<int, int>> vc(n, make_pair(-1, n));\n\n for (int i = 0; i < n; i++) {\n while (!sta.empty() && heights[i] <= heights[sta.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...
1
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<int>st,st1;\n #define ll long long \n\n int n=heights.size();\n vector<int>left(n,-1);\n for (int i = 0; i < n; i++) {\n while(st.size()>0 and heights[i]<=heights[st.top()])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...
1
{ "code": "/*\nBy :-: savetrees\nUsed :-: Monotonic Stack\n*/\nclass Solution {\npublic:\n vector<int> ps(vector<int> &height) {\n vector<int> p(height.size());\n stack<int> s;\n for (int i=0;i<height.size();i++) {\n while (!s.empty()&&height[s.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...
1
{ "code": "class Solution {\npublic:\n vector<int> ps(vector<int> &height) {\n vector<int> p(height.size());\n stack<int> s;\n for (int i=0;i<height.size();i++) {\n while (!s.empty()&&height[s.top()]>=height[i]) {\n s.pop();}\n if (s.empty()) {p[i] = -1;} \...
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> findNSE(vector<int>&arr){\n int n = arr.size();\n stack<int> stk;\n vector<int> ans(n);\n for(int i=n-1; i>=0; i--){\n while(!stk.empty() && arr[stk.top()] >= arr[i]) stk.pop();\n if(stk.empty()) ans[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...
2
{ "code": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int res = 0;\n vector<int> lefts = smallerLeft(heights);\n vector<int> rights = smallerRight(heights);\n\n for (int i = 0; i < heights.size(); i++) {\n int l = lefts[i] + 1;\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": "typedef struct node{\n int index;\n int height;\n};\nclass Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n stack<node> s;\n vector<int> maxs(heights.size(),0);\n s.push({0,heights[0]});\n maxs[0]=heights[0];\n \n for( int i=1;i<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...
2
{ "code": "class Solution {\npublic:\n vector<int> findSmall(const vector<int>& a) {\n vector<int> b(a.size(), -1);\n stack<int> s;\n\n for (int i = 0; i < a.size(); ++i) {\n while (!s.empty() && a[s.top()] > a[i]) {\n s.pop();\n }\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...
2
{ "code": "class Solution {\nprivate:\n struct Range {\n int begin;\n int end; // not included\n int tail;\n };\npublic:\n int largestRectangleArea(vector<int>& heights) {\n \n // The maximum area found so far.\n\n int maxArea = 0;\n\n // The total number of b...
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> left(n, -1);\n vector<int> right(n, n);\n\n stack<int> st;\n\n for(int i = 0; i < heights.size(); i++){\n while(!st.empty() && heights[st.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...
2
{ "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]...
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> 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]...
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\n{\npublic:\n int largestRectangleArea(vector<int> &heights)\n {\n // Intuition: Keep a monotonically increasing stack,\n // this means all heights on the stack will be less than the one in front of it\n // so this means, that when we encounter a height that is les...
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 len = heights.size();\n vector<int> left(len, -1);\n vector<int> right(len, len);\n vector<int> stk(len);\n stk[0] = 0;\n int sp = 1;\n for (int i = 1; i < len; ++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": "class Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n int n = heights.size();\n vector<int> leftMin(n, -1);\n vector<int> rightMin(n, n);\n stack<int> st;\n\n for(int i = 0; i < n; i++) {\n while(!st.empty() && heights[st.top()] >= h...
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 {\n\n// it is not a greedy approach, sorting does not solve it \n// brute force is getting each rectangle and evaluating the area \n// need to know nle and ple for each num in O(n)\n// if we know the ple and nle with its respective positions, we can compare the max area of those two and stor...
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 stack<int> index;\n vector<int> right(heights.size(), 0);\n vector<int> left (heights.size(), 0);\n int maxarea = 0;\n for(int i = 0; i < heights.size(); i++){\n while(!index.empt...
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;\nclass Solution {\npublic:\n int d1[100004];\n int d2[100004];\n int largestRectangleArea(vector<int>& heights) {\n memset(d2,-1,sizeof(d2));\n stack<pair<int,int>> st;\n int n = heights.size();\n st.push({heights[0],0});\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 {\n public:\n struct Pair {\n int index;\n int height;\n };\n\n int largestRectangleArea(vector<int>& heights) {\n int max_area = 0;\n std::vector<Pair> st;\n\n for (int i = 0; i < heights.size(); ++i) {\n int start = i;\n while (!st.empty() && st.back().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...
2
{ "code": "using ll = long long;\nclass Solution {\npublic:\n int largestRectangleArea(vector<int>& heights) {\n ll n = heights.size();\n auto a = heights;\n stack<int> st;\n vector<ll> nx(n+5,n);\n for(int i = n-1;i>=0;i--){\n while(not empty(st) and a[st.top()]>=a[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...
2
{ "code": "class Solution {\npublic:\n vector<int> nextSmallestElement(vector<int> arr) {\n stack<int> s;\n vector<int> ans(arr.size());\n\n s.push(-1);\n\n for (int i = arr.size() - 1; i >= 0; i--) {\n while (s.top() != -1 && arr[s.top()] >= arr[i]) {\n s.pop(...