id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 3 | {
"code": "\nclass Solution {\npublic:\n ListNode* swapNodes(ListNode* head, int k) {\n ListNode* temp=head;\n int n=0;\n while(temp!=NULL)\n {\n temp=temp->next;\n n++;\n }\n temp=head;\n int arr[n];\n for(int i=0;i<n,temp!=NULL;i++)\n ... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 3 | {
"code": "class Solution {\npublic:\n int Len(ListNode* head){\n if(!head) return 0;\n return 1 + Len(head->next); \n }\n ListNode* swapNodes(ListNode* head, int k) {\n // case 1: \n if(!head || !head->next) return head;\n int len = Len(head); \n int lpos = k;\n... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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 */\n\nclass Solution {\npublic:... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 3 | {
"code": "\nclass Solution {\npublic:\n int size(ListNode* head){\n int count = 0;\n while(head!=NULL){\n head = head->next;\n count++;\n }\n return count;\n }\n ListNode* swapNodes(ListNode* head, int k) {\n int len = size(head);\n vector<int>... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 3 | {
"code": "\n// decalre an array and store the values of LL in the array\n// then swap the kth from front and rear\n// again set the elements of array to LL\n\nclass Solution {\npublic:\n ListNode* swapNodes(ListNode* head, int k) {\n ListNode* temp= head;\n ListNode* len= head;\n int length = 0;\n\... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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 {\n ListN... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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 {\n \n ... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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// *... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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 {\n ListN... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 3 | {
"code": "\nclass Solution {\npublic:\nint i=1,j=-1,l=0;\nvoid helper_swap_nodes(ListNode*&start,ListNode*&t1,ListNode*&t2,ListNode*&t3,ListNode*&t4,ListNode*t,int k){\n if(t==nullptr)return;\n if(i==k-1){\n t1=t;\n t2=t1->next;\n // cout<<\"t1 marked at : \"<<t1->data<<\" & t2 marked at :... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 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 {\n vecto... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n\n int largestSubmatrix(vector<vector<int>>& matrix) \n {\n int len=matrix.size();\n int m=matrix[0].size();\n int maxarea=0;\n //say how many consecutive vertical 1's do we have at each row\n for(int i=1;i<len;i++)\n {\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& a) {\n \n int m=a.size();\n int n=a[0].size();\n int ans=0;\n for(int i=1;i<m;i++)\n {\n for(int j=0;j<n;j++)\n {\n if(a[i][j])\n a[i][j... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int mx=0;\n\n int n=matrix.size();\n int m=matrix[0].size();\n int sum=0;\n for(int j=0;j<m;j++)\n {\n sum=0;\n for(int i=0;i<n;i++)\n {\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& matrix, int i, int j, int steps) {\n int n = matrix.size();\n int m = matrix[0].size();\n\n matrix[i][j] = steps;\n\n if (i + 1 < n && matrix[i + 1][j] == 1)\n dfs(matrix, i + 1, j, steps + 1);\n }\n\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m=matrix.size();\n int n=matrix[0].size();\n \n for(int i=1;i<m;i++){\n \n for(int j=0;j<n;j++)\n if(matrix[i][j]==1)\n matrix[i][j]+=... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int nr=matrix.size();\n int nc=matrix[0].size();\n\n for(int i=1;i<nr;i++)\n {\n for(int j=0;j<nc;j++)\n {\n if(matrix[i][j]==1)\n {\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& g) {\n int m=g.size(), n=g[0].size();\n \n for(int j=0; j<n; ++j) {\n for(int i=0; i<m; ++i) {\n if(g[i][j] != 0) {\n g[i][j] = (i-1>=0 ? g[i-1][j] : 0) + 1;\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) \n {\n int m = matrix.size();\n int n = matrix[0].size();\n int ans =0 ;\n vector<int> arr(n,0);\n vector<int> temp;\n for(int i=0; i<m; i++)\n {\n for(int j=0; j<... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "#pragma GCC optimize(\"O3\")\nclass Solution {\npublic: \n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m=matrix.size(), n=matrix[0].size();\n int area=count(matrix[0].begin(), matrix[0].end(), 1);\n if (m==1) return area;\n if (n==1){\n #pragma unrol... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\n int getMax(vector<int>& v, int n)\n {\n int ans=0;\n for(int i=0; i<n; ++i)\n {\n ans=max(ans, v[i]*(i+1));\n }\n return ans;\n }\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int n=matrix.size();\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "\nauto _=[]()noexcept{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();\nclass Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n \n int n=matrix[0].size();\n int m=matrix.size();\n vector<pair<int,int>> prevheights;\n int area=0;\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m=matrix.size(), n=matrix[0].size();\n int area=count(matrix[0].begin(), matrix[0].end(), 1);\n for(int i=1; i<m; i++){\n #pragma unroll\n for(int j=0; j<n; j++){\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& mat)\n {\n ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // Accelerates\n\n const int ROWS = mat.size();\n const int COLS = mat[0].size();\n\n int result = 0;\n\n for (int i = 0; i < ROWS... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n for(int i = 1; i < m; i++){\n for(int j = 0; j < n; j++){\n if(matrix[i][j] == 1){\n matrix[i][j]+=matr... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& mat) {\n ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);\n int r=mat.size(),c=mat[0].size();\n int ans=0;\n for(int i=0;i<r;i++){\n for(int j=0;j<c;j++){\n if(mat[i][j]!=0 and i!=0... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int n=matrix.size();\n int m=matrix[0].size();\n int ans=0;\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n if(i==0 || !matrix[i][j] )continue;\n matri... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 1 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int r = matrix.size(), c = matrix[0].size();\n int res = 0;\n for(int i=0; i<r; ++i)\n {\n for(int j=0; j<c; ++j)\n {\n if(matrix[i][j] && i>0)\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& arr) {\n int n = arr.size();\n int m = arr[0].size();\n vector<int> height(m, 0);\n int ans = 0;\n for (int i = 0; i < n; i++)\n {\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m=matrix.size();\n int n=matrix[0].size();\n int ans=0;\n vector<int> height(n,0);\n for(int i=0;i<m;i++)\n {\n for(int j=0;j<n;j++)\n {\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n int max_area = 0;\n\n vector<int> heights(n,0);\n\n for(int i = 0;i<m;i++){\n\n for(int j = 0;j<n;j++){\n if... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n int max_area = 0;\n\n vector<int> heights(n,0);\n\n for(int i = 0;i<m;i++){\n\n for(int j = 0;j<n;j++){\n if... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& mat) {\n int n=mat.size();\n int m=mat[0].size();\n int res=0;\n auto mat2=mat;\n for(int i=1;i<n;i++){\n for(int j=0;j<m;j++)\n {\n if(mat[i][j])\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int n=matrix.size();\n int m=matrix[0].size();\n\n int maxi=INT_MIN;\n for(int i=0;i<n;i++)\n {\n vector<int>current;\n for(int j=0;j<m;j++)\n {\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int nr, nc;\n int largestSubmatrix(vector<vector<int>>& matrix) {\n nr = matrix.size();\n nc = matrix[0].size();\n int max_area = 0;\n\n for (int i = 0; i < nr; i++) {\n for (int j = 0; j < nc; j++) {\n if (matrix[i][j]... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n int maxArea = 0;\n\n // Step 1: Calculate the height of 1's for each column in every row.\n for (int i = 1; i < m; i++) {\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& mat) {\n int n=mat.size();\n int m=mat[0].size();\n int res=0;\n auto mat2=mat;\n for(int i=1;i<n;i++){\n for(int j=0;j<m;j++)\n {\n if(mat[i][j])\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n vector<int> dp(n);\n int res = 0;\n for (int i = 0; i < m; ++i) {\n map<int, int, greater<int>> counts;\n for (i... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& mtx) {\n int n = mtx.size();\n int m = mtx[0].size();\n vector<vector<int>> v(n, vector<int>(m, 0));\n\n for(int i = 0; i<m ; i++)\n {\n int x = 0;\n for(int j = 0 ;j<n; j++)\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n vector<vector<int>> sums(matrix.size(), vector<int>(matrix[0].size(), 0));\n for (int j = 0; j < matrix[0].size(); j++) {\n sums[0][j] = matrix[0][j];\n }\n for (int i = 1; i < matrix... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size(), n = matrix[0].size();\n vector<vector<int>> dp (m, vector<int> (n, 0));\n\n for(int i = 0; i < n; i++)\n {\n if(matrix[0][i]) dp[0][i]++;\n for(int j... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m=size(matrix);\n int n=size(matrix[0]);\n int max_area=0;\n vector<int> heights(n,0);\n\n for(int i=0;i<m;i++){\n\n for(int j=0;j<n;j++){\n if(matrix[i][j]=... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size(), n = matrix[0].size(), res = 0;\n vector<vector<int>> count(m + 1, vector<int>(n, 0));\n for(int j = 0; j < n; j++){\n for(int i = m - 1; i >= 0; i--){\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\n int getMax(vector<int>& v, int n) {\n int ans = 0;\n for (int i = 0; i < n; ++i) {\n ans = max(ans, v[i] * (i + 1));\n }\n return ans;\n }\n\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int n = matrix.size();\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 2 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m=matrix.size(),n=matrix[0].size(),b[m][n],ret=0;\n for (int j=0;j<n;j++){\n int x=0;\n for (int i=m-1;i>=0;i--){\n if (matrix[i][j]==1) x++;\n else x=0... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n // for each i j where el==1\n // count how many 1 it has from j to j-1;\n // then iterate over each row;\n // for each row, take a pq and push the count of 1s for each el;\n // then itera... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n \n int total=0;\n \n for(int i=0;i<matrix[0].size();i++){\n for(int j=1;j<matrix.size();j++){\n if(matrix[j][i]) matrix[j][i]+=matrix[j-1][i];\n }\n }\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int n=matrix.size();\n int m=matrix[0].size();\n for(int i=0;i<m;i++){\n int val=0;\n for(int j=n-1;j>=0;j--){\n val+=matrix[j][i];\n if(matrix[j][i]... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& mat) {\n int n=mat.size(), m= mat[0].size(), ans=0;\n vector<int>prefix(m,0); \n for(int i=0;i<n;i++){\n vector<int>curr(m,0);\n for(int j=0;j<m;j++){\n if(mat[i][j]==0)... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n int maxArea = INT_MIN;\n vector<int>prev(n,0);\n for(int i=0;i<m;i++){\n vector<int>curr(n,0);\n for(int j=0;j<n... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n\n //APPROACH 1: {BRUTE FORCE}:\n // int m = matrix.size();\n // int n = matrix[0].size();\n\n // int maxArea = 0;\n\n // for(int i=0;i<m;i++)\n // {\n // ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n // Approach 2 without modifying the original matrix\n int m = matrix.size();\n int n = matrix[0].size();\n int maxArea=0;\n vector<int> prevrow(n,0);\n for(int row=0;row<m;row++){\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "/* \ngiven a binary matrix, return the area of the largest submatrix that is all 1s after reordering columns.\n\nhave acount of the number of 1s in each row then you can use a sliding window to find all the consecutive\nrows that have 1s and compute the area at the end\n*/\n\nclass Solution {\npublic:\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& grid) {\n int m = grid.size(); int n = grid[0].size();\n int res = 0;\n vector<int>col(n, 0);\n for (int i = 0; i < m; i++){\n for (int j = 0; j < n; j++){\n if (grid[i][j]){col[j]... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size(),n = matrix[0].size();\n int maxArea = 0;\n vector<vector<int>>heights = matrix;\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n if(i>0 && height... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size(),n = matrix[0].size();\n int ans = 0;\n vector<vector<int>>height = matrix;\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n if(i>0 && height[i][j... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int n = matrix.size();\n int m = matrix[0].size();\n vector<vector<int>> prefix(n,vector<int> (m));\n for(int j=0;j<m;j++)\n {\n prefix[0][j] = matrix[0][j];\n }\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int n = matrix.size();\n int m = matrix[0].size();\n vector<vector<int>> prefix(n,vector<int> (m));\n for(int j=0;j<m;j++)\n {\n prefix[0][j] = matrix[0][j];\n }\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int n = matrix.size();\n int m = matrix[0].size();\n vector<vector<int>> prefix(n,vector<int> (m));\n for(int j=0;j<m;j++)\n {\n prefix[0][j] = matrix[0][j];\n }\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int tmp = 0;\n vector<vector<int>> unor(matrix.size());\n for (int j = 0; j != matrix[0].size(); ++j) \n {\n tmp = 0;\n for (int i = 0; i != matrix.size(); ++i) \n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int tmp = 0;\n vector<vector<int>> unor(matrix.size());\n for (int j = 0; j != matrix[0].size(); ++j) \n {\n tmp = 0;\n for (int i = 0; i != matrix.size(); ++i) \n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int tmp = 0;\n vector<vector<int>> unor(matrix.size());\n for (int j = 0; j != matrix[0].size(); ++j) \n {\n tmp = 0;\n for (int i = 0; i != matrix.size(); ++i) \n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n vector<vector<int>> copy = matrix;\n int ans = 0;\n int n = matrix.size(), m = matrix[0].size();\n for(int row = 0; row<n; row++){\n for(int col = 0; col<m; col++){\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n vector<pair<int,int>> prevHeights;\n int ans = 0;\n \n for (int row = 0; row < m; row++) {\n vector<pair<int,int>> h... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m=matrix.size(), n=matrix[0].size();\n int ans=0;\n \n vector<pair<int, int>> bars;\n for (int row=0; row<m; row++) {\n vector<pair<int, int>> bars2;\n vector<bo... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size(), n = matrix[0].size();\n int res = 0;\n vector<pair<int, int>> cand;\n for (int i = 0; i < m; ++i) {\n vector<pair<int, int>> temp;\n vector<bool> see... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m=matrix.size(), n=matrix[0].size();\n int ans=0;\n \n vector<pair<int, int>> bars;\n for (int row=0; row<m; row++) {\n vector<pair<int, int>> bars2;\n vector<bo... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int n=matrix.size();\n int m=matrix[0].size();\n vector<vector<int>>hash(n,vector<int>(m));\n for(int i=0;i<m;i++)\n {\n int cnt=0;\n for(int j=0;j<n;j++)\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int ans=0;\n void fn(vector<int>temp){\n sort(begin(temp),end(temp));\n int z=temp[temp.size()-1];\n int w=1;\n for(int i=temp.size()-1;i>=0;i--){\n z=min(z,temp[i]);\n w=(temp.size()-1-i+1);\n ans=max(ans,(z*w))... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int n = matrix.size(), m = matrix[0].size();\n vector<vector<int>> histogram(n, vector<int>(m, 0));\n for(int j = 0; j < m; j++)\n for(int i = 0; i < n; i++) {\n histogram[i][... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int n = matrix.size();\n int m = matrix[0].size();\n vector<vector<int>> prefix(n, vector<int>(m, 0));\n\n\n for (int i = 0; i < m; i++) {\n prefix[0][i] = matrix[0][i];\n }\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int n = matrix.size();\n int m = matrix[0].size();\n vector<vector<int>> prefix(n, vector<int>(m, 0));\n\n\n for (int i = 0; i < m; i++) {\n prefix[0][i] = matrix[0][i];\n }\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int row = matrix.size();\n int col = matrix[0].size();\n\n // Step 1: Calculate column heights (sum of consecutive 1s)\n for (int j = 0; j < col; j++) {\n for (int i = 1; i < row; i++... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n int ans = 0;\n vector<pair<int,int>> prevHeights;\n \n for(int i = 0;i<m;i++){\n vector<pair<int,int>> Heights;\n ... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n vector<pair<int, int>> prevHeights;\n int ans = 0;\n \n for (int row = 0; row < m; row++) {\n vector<pair<int, int>>... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "/*\nApproach 1 - Sort By Height On Each Baseline Row\nLet's modify matrix so that each matrix[row][col] represents the following value: \nhow many consecutive 1s are there till matrix[row] are i that in that col.\nSince we can swap columns or change column order we can also sort the consecutive ones till t... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int rows = matrix.size(), cols = matrix[0].size();\n vector<pair<int,int>> prevHeight;\n int maxArea = 0;\n \n for(int i=0; i<rows; i++)\n {\n vector<pair<int,int>> curr... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "/*\nApproach 1 - Sort By Height On Each Baseline Row\nLet's modify matrix so that each matrix[row][col] represents the following value: \nhow many consecutive 1s are there till matrix[row] are i that in that col.\nSince we can swap columns or change column order we can also sort the consecutive ones till t... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n vector<pair<int,int>> prevHeights;\n int ans = 0;\n \n for (int row = 0; row < m; row++) {\n vector<pair<int,int>> h... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\nprivate:\n void computeColumnArea(vector< vector<int> > &A, int col, vector< priority_queue<int> > &rows_height)\n {\n int n = A.size();\n int m = A[0].size();\n \n vector<int> column_area(n, 0);\n column_area[0] = A[0][col];\n if(column_are... |
1,845 | <p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>
<p>Return <em>the area of the largest submatrix within </em><code>matrix</code><em> where <strong>every</strong> element of the sub... | 3 | {
"code": "class Solution {\npublic:\n int largestSubmatrix(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n vector<pair<int,int>>prevRow;\n int maxArea = 0;\n for(int i=0;i<m;i++){\n vector<int>visited(n,0);\n vector<pai... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 0 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n int i1 = 0, i2 = 0;\n while(i1 < nums1.size() && i2 < nums2.size())\n {\n if(nums1[i1] == nums2[i2])\n return nums1[i1];\n else if(nums1[i1] > nums2[i2])\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 0 | {
"code": "bool init = [](){cin.tie(0);ios::sync_with_stdio(0);return false;}();\nclass Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n int i=0, j=0;\n while(i<nums1.size() && j<nums2.size()){\n if(nums1[i]>nums2[j]){\n j++;\n }else... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 0 | {
"code": "class Solution {\npublic:\n int speedup = []{\n std::ios::sync_with_stdio(0);\n std::cin.tie(0);\n std::cout.tie(0);\n return 0;\n }();\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n for (int x: nums1) {\n if (binary_search(nums2.begin(), ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 0 | {
"code": "class Solution {\npublic:\n int speedup = []{\n std::ios::sync_with_stdio(0);\n std::cin.tie(0);\n std::cout.tie(0);\n return 0;\n }();\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n for (int x: nums1) {\n if (binary_search(nums2.begin(), ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 0 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n int i = 0, j = 0, n1 = nums1.size(), n2 = nums2.size();\n\n while (i < n1 && j < n2) {\n if (nums1[i] == nums2[j])\n return nums1[i];\n else if (nums1[i] < nums2[j]) {... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.