id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,765 | <p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p>
<p>Remove <code>list1</code>'s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p>
<p>The bl... | 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... |
1,765 | <p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p>
<p>Remove <code>list1</code>'s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p>
<p>The bl... | 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... |
1,765 | <p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p>
<p>Remove <code>list1</code>'s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p>
<p>The bl... | 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... |
1,765 | <p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p>
<p>Remove <code>list1</code>'s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p>
<p>The bl... | 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... |
1,765 | <p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p>
<p>Remove <code>list1</code>'s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p>
<p>The bl... | 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... |
1,765 | <p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p>
<p>Remove <code>list1</code>'s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p>
<p>The bl... | 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... |
1,765 | <p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p>
<p>Remove <code>list1</code>'s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p>
<p>The bl... | 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... |
1,765 | <p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p>
<p>Remove <code>list1</code>'s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p>
<p>The bl... | 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... |
1,765 | <p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p>
<p>Remove <code>list1</code>'s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p>
<p>The bl... | 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... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "#pragma GCC optimize(\"Ofast,unroll-loops,inline\")\n#pragma GCC target(\"avx,mmx,sse2,sse3,sse4\")\nstatic const auto fast_io = []() { ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();\n\nclass Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n cons... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"avx,mmx,sse2,sse3,sse4\")\nstatic const auto fast_io = []() { ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();\n\nclass Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n const int ROWS = land.si... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n vector<vector<int>> ans;\n int m = land.size();\n int n = land[0].size();\n for (int i = 0; i < m; ++i) {\n for (int j = 0; j < n; ++j) {\n if (land[i][j] == ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "class Solution {\npublic:\n void dfs(vector <vector <int>> &land, int i, int j, int &r, int &c) {\n if (i < 0 || j < 0 || i >= land.size() || j >= land[0].size() || land[i][j] == 0 || land[i][j] == -1) {\n return;\n }\n land[i][j] = -1;\n r = max(r, i);\n c ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n \n int m = land.size();\n int n = land[0].size();\n vector<vector<int>> res;\n for (int i = 0; i < m; i++)\n {\n for (int j = 0; j < n; j++)\n {\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n vector<vector<int>> result;\n int m = land.size();\n int n = land[0].size();\n \n for (int i = 0; i < m; ++i) {\n for (int j = 0; j < n; ++j) {\n if (l... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n int m = land.size();\n int n = land[0].size();\n vector<vector<int>> result;\n\n for (int i = 0; i < m; ++i) {\n for (int j = 0; j < n; ++j) {\n \n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n void dfs(vector<vector<int>>& land, int r, int c, int& r2, int& c2) {\n // Base case: if out of bounds or not farmland ('0')\n if (r < 0 || r >= land.size() || c < 0 || c >= land[0].size() || land[r][c] == 0) {\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "class Solution {\npublic:\n int row[4] = {0, 1};\n int col[4] = {1, 0};\n void dfs(int r, int c, vector<vector<bool>> &vis, vector<vector<int>>& land, int &l1, int &l2) {\n vis[r][c] = true;\n if(r > l1) {\n l1 = r;\n l2 = c;\n }\n else if(r == l1 ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "class Solution {\npublic:\n // Depth First Search (DFS) function to explore the land area\n void dfs(int i, int j, vector<vector<int>>& a, vector<vector<bool>>& v, int &ri, int &rj) {\n int n=a.size(),m=a[0].size();\n v[i][j] = true;\n if (i + 1 <n && a[i + 1][j] == 1 && !v[i + 1... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n vector<pair<int,int>> dir = {{1,0}, {0,1}};\n vector<vector<int>> ans ;\n int m = land.size();\n int n = land[0].size();\n queue<pair<int,int>> q;\n for(int i = 0 ; i < m... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& g) {\n\nint n=g.size(),m=g[0].size();\n\nvector<vector<int>> ans; \n\nqueue<pair<int,int>> q;\n\n \n\nfor(int i=0;i<n;i++)\n\n for(int j=0;j<m;j++)\n\n if(g[i][j]){\n \n pair<int,int>p={i,j};\... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n vector<vector<int>> list;\n int n = land.size();\n int m = land[0].size();\n\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if (land[i][j] ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 0 | {
"code": "class Solution {\npublic:\n void markVisited(vector<vector<int>>& land, int r1, int c1, int r2, int c2) {\n for (int i = r1; i <= r2; ++i) {\n for (int j = c1; j <= c2; ++j) {\n land[i][j] = 0;\n }\n }\n\n return;\n }\n\n vector<vector<int>... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n const int m = land.size();\n const int n = land[0].size();\n vector<vector<int>> group;\n for(int i = 0; i < m; i++){\n for(int j = 0; j < n; j++){\n if(land... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n int n, m;\n n = land.size();\n m = land[0].size();\n vector<vector<int>>result;\n vector<vector<bool>>visited(n, vector<bool>(m, false));\n for(int i = 0; i < n; i++){\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n int m = land.size(), n = land[0].size();\n vector<vector<int>> ans;\n\n vector<vector<pair<int, int>>> dp(m + 1, vector<pair<int, int>>(n + 1));\n\n for (int i = 0; i < m; i++) {\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n\n int r, c;\n\n int row[4] = {1, -1, 0, 0};\n int col[4] = {0, 0, 1, -1};\n\n bool valid(int i, int j) {\n if (i >= 0 && i < r && j >= 0 && j < c)\n return true;\n return false;\n }\n\n vector<vector<int>> findFarmland(vector<vector<int... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n int m=land.size(), n=land[0].size();\n\n vector<vector<int>> ans;\n\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n if(land[i][j]==1 && ((i==0 || land[i-1][j]==0) ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\n void dfs(int r , int c, vector<vector<int>>&land, vector<vector<int>>&vis, vector<pair<int,int>>&dir,vector<int>&temp,int &X,int &Y){\n vis[r][c]=1;\n int n = land.size();\n int m = land[0].size();\n for(auto it:dir){\n int i = r+it.first,j=c+it... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n // Depth First Search (DFS) function to explore the land area\n void dfs(int i, int j, vector<vector<int>>& a, vector<vector<int>>& v, int &ri, int &rj) {\n // Mark the current cell as visited\n v[i][j] = 1;\n\n // Explore the neighboring cells in the ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\nvoid dfs(vector<vector<int>>&grid,int r,int c,int &maxr,int &maxc){\n int nr=grid.size();\n int nc=grid[0].size();\n if (r < 0 || c < 0 || r >= nr || c >= nc || grid[r][c] == 0) {\n return;\n }\n grid[r][c] = 0;\n maxr=max(ma... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\n\npublic:\nint n,m;\nvector<vector<int>>directions{{1,0},{-1,0},{0,1},{0,-1}};\n void dfs(int row,int col,int &row1,int &col1,vector<vector<int>>&land){\n if(row>=n || row<0 || col>=m || col<0 || land[row][col]==0){\n return;\n }\n land[row][col]=0;\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n void dfs(int i, int j, vector<vector<int>>& land, int& xmin, int& ymin, int& xmax, int& ymax){\n int dx[4]= {0,-1,0,1};\n int dy[4]= {1,0,-1,0};\n xmin= min(xmin,i);\n xmax= max(xmax,i);\n ymin= min(ymin,j);\n ymax= max(ymax,j);\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n\n void dfs(vector<vector<int>> &land, int r, int c, int &mr, int &mc)\n {\n if (r < 0 || r >= land.size() || c < 0 || c >= land[0].size() || land[r][c] == 0)\n return;\n\n mr = max(r, mr);\n mc = max(c, mc);\n\n land[r][c] = 0;\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n \n void dfs(vector<vector<int>> &land,int i,int j,int &hr,int &hc)\n {\n int r=land.size();\n int c=land[0].size();\n land[i][j]=0;\n hr=max(hr,i);\n hc=max(hc,j);\n if(i-1>=0&& land[i-1][j]==1) dfs(land,i-1,j,hr,hc);\n if(i+1<r&& land[i+1][j]==1... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\nvoid dfs(vector<vector<int>>& land,int r,int c,int n,int m,int &maxi,int &maxj)\n{\n land[r][c]=0;\n maxi=max(maxi,r);\n maxj=max(maxj,c);\n int dr[]={-1,0,1,0};\n int dc[]={0,1,0,-1};\n for(int i=0;i<4;i++)\n {\n int nrow=r+dr[i];\n int ncol=c+dc[i];\n if(... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n\n void dfs(int i , int j, vector<vector<int>>& land, vector<int>&cor){\n int n = land.size(), m = land[0].size();\n\n if(i < 0 || j < 0 || i>=n || j >=m || land[i][j] == 0)return;\n\n land[i][j] = 0;\n\n cor[2]= max(i, cor[2]);\n cor[3]= max... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\n public:\n void dfs(vector<vector<int>>& land , int i, int j, vector<int>& farm)\n {\n if(i<0||j<0||i>=land.size()||j>=land[0].size()||land[i][j]==0)\n {\n return;\n }\n land[i][j]=0;\n farm[2]=max(farm[2],i);\n farm[3]=max(far... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& land, int r, int c, vector<int>& bounds) {\n int nr = land.size();\n int nc = land[0].size();\n \n land[r][c] = 0;\n \n bounds[2] = max(bounds[2], r);\n bounds[3] = max(bounds[3], c);\n \n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n vector<int>dx{0,0,1,-1};\n vector<int>dy{1,-1,0,0};\n\n void f(int x,int y,int &r,int &c,int n,int m,vector<vector<int>>& land) {\n if(x<0 || y<0 || x>=n || y>=m || land[x][y]==0 || land[x][y]==2)\n return;\n land[x][y]=2;\n r=max(r,x);\n... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n int n, m;\n int dr[4] = {-1, 0, 1, 0};\n int dc[4] = {0, 1, 0, -1};\n vector<vector<int>> ans;\n void dfs(int i, int j, int &r2, int &c2, vector<vector<int>>& land)\n {\n land[i][j] = -1;\n\n r2 = max(r2, i);\n c2 = max(c2, j);\n\n f... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n void f(vector<vector<int>>& vis, int startr, int startc, int maxr, int maxc){\n for(int i=startr; i<=maxr; i++){\n for(int j=startc; j<=maxc; j++){\n vis[i][j] = 1;\n }\n }\n }\n void dfs(vector<vector<int>>& land, int ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n vector<pair<int, int>>n = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};\n void dfs(vector<vector<int>>& land, vector<vector<int>>& visited, int cRow, int cCol, int& bl, int &br){\n visited[cRow][cCol] = true;\n if(cRow >= bl && cCol >= br){\n bl = cRow;\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 1 | {
"code": "class Solution {\npublic:\n vector<pair<int, int>>n = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};\n void dfs(vector<vector<int>>& land, vector<vector<int>>& visited, int cRow, int cCol, int& bl, int &br){\n visited[cRow][cCol] = true;\n if(cRow >= bl && cCol >= br){\n bl = cRow;\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 2 | {
"code": "class Solution {\npublic:\n vector<int> rowDiff= {-1, 0, 0, 1};\n vector<int> colDiff= {0, -1, 1, 0};\n\n\n void dfs (vector<vector<int>>& land, vector<vector<int>>& visited, vector<int>& temp, int i, int j) {\n visited[i][j] = 1;\n temp[0]= min(temp[0], i);\n temp[1]= min(tem... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 2 | {
"code": "class Solution {\npublic:\n vector<int> rowDiff= {-1, 0, 0, 1};\n vector<int> colDiff= {0, -1, 1, 0};\n\n\n void dfs (vector<vector<int>>& land, vector<vector<int>>& visited, vector<int>& temp, int i, int j) {\n visited[i][j] = 1;\n temp[0]= min(temp[0], i);\n temp[1]= min(tem... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 2 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>> &land,int r,int c, int &lr, int &lc){\n int nr=land.size();\n int nc=land[0].size();\n land[r][c]=0;\n lr=max(lr,r); //lr=(lr>r)?lr:r;\n lc=max(lc,c); //lc=(lc>c)?lc:c;\n if(r-1>=0 && land[r-1][c]==1) dfs(... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 2 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& grid, int r, int c, int& lr, int& lc) {\n int nr = grid.size();\n int nc = grid[0].size();\n lr = max(r, lr);\n lc = max(c, lc);\n grid[r][c] = 0; \n if (r - 1 >= 0 && grid[r - 1][c] == 1) dfs(grid, r - 1... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 2 | {
"code": "class Solution {\n void dfs(vector<vector<int>>& grid, int r, int c, pair<int,int>& bc)\n {\n if(r>bc.first) bc.first=r;\n if(c>bc.second) bc.second=c;\n grid[r][c]=-1;\n if(r-1>=0 && grid[r-1][c]==1) dfs(grid, r-1, c,bc);\n if(r+1<grid.size() && grid[r+1][c]==1) df... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>>visited;\n pair<int,int>maxi;\n void dfs(vector<vector<int>>& grid,int i,int j)\n {\n int n=grid.size();\n int m=grid[0].size();\n if(i<0||i>=n||j<0||j>=m||visited[i][j]==1||grid[i][j]==0)\n return;\n maxi=max(maxi,{i,j}... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 2 | {
"code": "class Solution {\npublic:\nint lr=0,lc=0;\n void dfs(vector<vector<int>>& land,int r,int c){\n int nr=land.size();\n int nc=land[0].size();\n land[r][c]=0;\n lr =(lr>r)?lr:r;\n lc = (lc>c)?lc:c;\n if(r-1>=0 && land[r-1][c]==1) dfs(land,r-1,c);\n if(r+1<nr && land[r+1][c]==1)... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 2 | {
"code": "class Solution {\npublic:\n int lr=0,lc=0;\n void dfs(vector<vector<int>>& land,int i,int j){\n int nr=land.size();\n int nc=land[0].size();\n land[i][j]=0;\n lr=(lr>i)?lr:i;\n lc=(lc>j)?lc:j;\n if(i-1 >= 0 && land[i-1][j]==1) dfs(land,i-1,j);\n if(i+1... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 2 | {
"code": "class Solution {\npublic:\n bool isValid(int r, int c, vector<vector<int>>& land) {\n if (r < 0 || r >= land.size())\n return false;\n if (c < 0 || c >= land[0].size())\n return false;\n\n return true;\n }\n void DFS(int r, int c, vector<vector<int>>& lan... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 2 | {
"code": "class Solution {\npublic:\n bool isValid(int r, int c, vector<vector<int>>& land) {\n if (r < 0 || r >= land.size())\n return false;\n if (c < 0 || c >= land[0].size())\n return false;\n\n return true;\n }\n void DFS(int r, int c, vector<vector<int>>& lan... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "\nclass Solution {\nprivate:\n int lr = 0, lc = 0;\n vector<vector<int>> ans;\n\n void dfs(vector<vector<int>>& land, int r, int c) {\n int nr = land.size();\n int nc = land[0].size();\n\n lr = max(lr, r);\n lc = max(lc, c);\n \n land[r][c] = 0; \n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>>ans;\n void dfs(vector<vector<int>>& land,int i,int j,int &maxi,int &maxj){\n if(i<0 || j<0 ||i==land.size() || j==land[0].size() || land[i][j]==0){\n return;\n }\n land[i][j]=0;\n maxi=max(maxi,i);\n maxj=m... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n\nvoid dfs(int i,int j,vector<vector<int>>& grid,vector<int>& ans){\n \n\n \n if(i<0 ||i>=grid.size()||j<0||j>=grid[0].size()||grid[i][j]==0)return;\n grid[i][j]=0;\n\n if(ans[0]==-1 && ans[1]==-1){\n ans[0]=i;\n ans[1]=j;\n }\n\n if(ans[2]<=i |... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\nprivate:\n void dfs(vector<vector<int>>& land, vector<vector<bool>>& visited, int r, int c, int& r2, int& c2) {\n // If out of bounds or already visited or not farmland, return\n if (r < 0 || r >= land.size() || c < 0 || c >= land[0].size() || visited[r][c] || land[r][c] ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class DisjointSet{\n \n public:\n vector<int> rank, parent;\n int count;\n DisjointSet(int n){\n rank.resize(n,0);\n parent.resize(n);\n for(int i=0; i<n; i++){\n parent[i] = i;\n }\n }\n\n int findPar(int u){\n if(parent[u] == u) return pa... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class DisjointSet{\n \n public:\n vector<int> rank, parent;\n int count;\n DisjointSet(int n){\n rank.resize(n,0);\n parent.resize(n);\n for(int i=0; i<n; i++){\n parent[i] = i;\n }\n }\n\n int findPar(int u){\n if(parent[u] == u) return pa... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int r, int c, vector<vector<int>>&grid, vector<vector<int>>&visi, int &maxr, int &maxc)\n {\n visi[r][c]=1;\n if(r>maxr)\n {\n maxr=r;\n }\n if(c>maxc)\n {\n maxc=c;\n }\n if(r>0&&grid[r... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n int dirx[4] = {0, 0, -1, 1};\n int diry[4] = {1, -1, 0, 0};\n\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n int n = land.size(), m = land[0].size();\n vector<vector<int>> vis(n, vector<int>(m, 0));\n int count = 0;\n\n for... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n int row[4] = {-1, 0, 1, 0};\n int col[4] = {0, 1, 0, -1};\n void dfs(int r, int c, vector<vector<bool>> &vis, vector<vector<int>>& land, pair<int, int> &s, pair<int, int> &l) {\n vis[r][c] = true;\n s = min(s, make_pair(r, c));\n l = max(l, make_pai... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n int m = land.size();\n int n = land[0].size();\n vector<vector<bool>> visited(m, vector<bool>(n, false));\n vector<vector<int>> lands;\n\n for (int i = 0; i < m; ++i) {\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n vector<vector<int>> ans;\n map<int,int> m;\n int s=land[0].size();\n for(int i=0;i<land.size();i++){\n for(int j=0;j<s;j++){\n if(land[i][j]==1){\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n vector<vector<int>> ans;\n map<int,int> m;\n int s=land[0].size();\n for(int i=0;i<land.size();i++){\n for(int j=0;j<s;j++){\n if(land[i][j]==1){\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n\n\n void dfs(vector<vector<int>>& grid, vector<vector<bool>>& visited,int r,int c,int* mr,int* mc)\n {\n int m=grid.size();\n int n=grid[0].size();\n visited[r][c]=true;\n int nr,nc;\n\n for(int i=-1;i<=1;i++)\n {\n nr=r... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findFarmland(vector<vector<int>>& land) {\n vector<vector<bool>> visited(land.size(), vector<bool>(land[0].size(), false));\n vector<vector<int>> ans;\n for (int row1 = 0; row1 < land.size(); row1++) {\n for (int col1 = 0; c... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\nint pi=0;\nint pj=0;\nint delr[4]={-1,1,0,0};\nint delc[4]={0,0,-1,1};\nvoid dfs(vector<vector<int>>&land,vector<vector<int>>&vis,int r,int c,vector<pair<int,int>>&pk){\n vis[r][c]=1;\n pk.push_back({r,c});\n for(int i=0;i<4;i++){\n int nr=delr[i]+r;\n in... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> poss={{0,1},{0,-1},{-1,0},{1,0}};\n void dfs(vector<vector<int>>& land, int i, int j, int m, int n, vector<vector<int>>& vis, vector<pair<int,int>>& travs){\n vis[i][j]=1;\n travs.push_back({i,j});\n for(int k=0;k<4;k++){\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n\n void dfs(int i,int j,int n,int m,vector<int>&row,vector<vector<int>>&land){\n\n if(i<0 || i>=n || j<0 || j>=m || land[i][j]==0){\n return;\n } \n if(land[i][j]==-1)return;\n\n land[i][j]=-1;\n\n // push the adjacent coordinates... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n\n void dfs(int i,int j,int n,int m,vector<int>&row,vector<vector<int>>&land){\n\n if(i<0 || i>=n || j<0 || j>=m || land[i][j]==0){\n return;\n } \n if(land[i][j]==-1)return;\n\n land[i][j]=-1;\n\n // push the adjacent coordinates... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n\n void dfs(int i,int j,int n,int m,vector<int>&row,vector<vector<int>>&land){\n\n if(i<0 || i>=n || j<0 || j>=m || land[i][j]==0){\n return;\n } \n if(land[i][j]==-1)return;\n\n land[i][j]=-1;\n\n // push the adjacent coordinates... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int i, int j, vector<vector<int>>& land, int n, int m,\n vector<pair<int, int>>& ans, vector<vector<int>>& visit) {\n if (i < 0 || i >= n || j < 0 || j >= m) {\n return;\n }\n if (land[i][j] == 0) {\n return;\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& land,vector<vector<bool>>& visited,int i,int j,int& small_x,int& small_y,int& big_x,int& big_y){\n if(i<0 || i>=land.size() || j<0 || j>=land[0].size() || visited[i][j] || land[i][j]==0){\n return;\n }\n visited[i]... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void coverall(vector<vector<int>>&land,vector<vector<bool>>&visted,int i,int j,int &lasti,int &lastj)\n {\n if(i<0||i>=land.size()||j<0||j>=land[0].size()||land[i][j]==0||visted[i][j]==true)\n {\n return ;\n }\n visted[i][j]=true;\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<int>>& land,vector<int> &coord,vector<vector<int>> &vis,int i,int j)\n {\n vis[i][j]=1;\n\n int dx[4]={-1,0,1,0};\n int dy[4]={0,1,0,-1};\n if(i+1>=land.size() && j+1>=land[0].size())\n {\n coord.push_b... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& land , int row , int col , vector<vector<bool>> &vis , int &lr , int &lc){\n vis[row][col] = true;\n int nr = land.size();\n int nc = land[0].size();\n lr = max(lr,row);\n lc = max(lc,col);\n if(row-1>=0 ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& land , int row , int col , vector<vector<bool>> &vis , int &lr , int &lc){\n vis[row][col] = true;\n int nr = land.size();\n int nc = land[0].size();\n lr = max(lr,row);\n lc = max(lc,col);\n if(row-1>=0 ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n vector<int> dfs(vector<vector<int>>& grid, int i,int j,int n,int m){\n grid[i][j]=0;\n int dir[5]={-1,0,1,0,-1};\n vector<int> curr={i,j};\n for(int d=0;d<4;d++){\n int x=i+dir[d];\n int y=j+dir[d+1];\n if(x<0 || x>... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int i, int j, vector<vector<int>>& grid, vector<vector<bool>>& visited,int &cntx,int &cnty) {\n visited[i][j] = true;\n \n int dx[] = {1, -1, 0, 0};\n int dy[] = {0, 0, 1, -1};\ncntx = max(cntx, i);\n cnty = max(cnty, j);\n f... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n vector<pair<int, int>> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n\n void dfs(vector<vector<int>>& land, int m, int n, int i, int j, vector<vector<bool>>& visited, vector<int>& temp)\n {\n for(auto it : dir)\n {\n int x = i+it.first;\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n int dx[4] = {-1, 0, 1, 0};\n int dy[4] = {0, 1, 0, -1};\n \n void bfs(int row, int col, vector<vector<int>>& land, vector<int>& temp, \n vector<pair<int, int>>& v, vector<vector<int>>& visited) {\n visited[row][col] = true; \n v.push_back({r... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void solve(int i,int j,vector<vector<int>>& v,vector<vector<bool>>& vis\n ,pair<int,int>&p)\n {\n if(v[i][j]==0)\n return;\n \n if(i+1<v.size() && !vis[i+1][j])\n {\n vis[i+1][j]=true;\n if(v[i+1][j]==1)\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int i, int j, vector<vector<bool>> &vis, vector<vector<int>>& land, int n, int m, vector<int> &dr, vector<int> &dc, int &maxi, int &maxj){\n\n vis[i][j] = true;\n maxi = max(maxi, i);\n maxj = max(maxj, j);\n\n for(int k=0; k<4; k++){\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& land, vector<vector<bool>>& vis, int r, int c, vector<int>& temp) {\n int row = land.size();\n int col = land[0].size();\n vis[r][c] = true; \n if (c == col - 1 && r == row - 1) {\n temp.push_back(r)... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n int m,n;\n vector<vector<int>>directions{{1,0},{-1,0},{0,1},{0,-1}};\n void dfs(vector<vector<int>>& land,int&l,int &r,int &i,int &j)\n {\n\n if(i<0 || j<0 || i>=m || j>=n || land[i][j]==0 )\n return;\n \n if(land[i][j]==-1)\n ... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& land, vector<vector<bool>>& visit, int i, int j, int& curx, int& cury) {\n int n = land.size();\n int m = land[0].size();\n \n visit[i][j] = true;\n curx = max(curx, i);\n cury = max(cury, j);\n \n... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n bool isValid(vector<vector<int>>& land,int i,int j)\n {\n if(i>=0 && i<land.size() && j>=0 && j<land[0].size())\n return true;\n return false;\n }\n void traversal(vector<vector<int>>& land,int i,int j,int &r,int &c)\n {\n vector<pair<i... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\nprivate:\n void getRightBottomCords(vector<vector<int>> &land, int row, int col, int &sx, int &sy) {\n vector<int> x = {-1, 1, 0, 0};\n vector<int> y = {0, 0, -1, 1};\n for(int i=0;i<4;i++) {\n int newX = row + x[i];\n int newY = col + y[i];\n... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void find(vector<vector<int>>&land,vector<pair<int,int>>&vec,vector<vector<int>>&vis,int i,int j,int m,int n)\n {\n vis[i][j]=1;\n vec.push_back({i,j});\n if(i-1>=0 && land[i-1][j]==1 && !vis[i-1][j])\n {\n find(land,vec,vis,i-1,j,m,n... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\n #define pb push_back\n int x=0, y=0;\npublic:\n void dfs(int i, int j, vector<vector<int>>& land, vector<vector<bool>>& vis, int n, int m) {\n vis[i][j] = true;\n x = max(x, i);\n y = max(y, j);\n if(i-1>=0 && !vis[i-1][j] && land[i-1][j]==1) dfs(i-1... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int row, int col, vector<vector<int>>& visited, vector<vector<int>>& land, int& r2, int& c2){\n // mark the cell as visited\n visited[row][col] = 1;\n // visiting the neighbours\n // update the boundaries of the current farmland\n r... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int row, int col, vector<vector<int>>& visited, vector<vector<int>>& land, int& r2, int& c2){\n // mark the cell as visited\n visited[row][col] = 1;\n // update the boundaries of the current farmland\n r2 = max(r2, row);\n c2 = max(... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int x,int y,vector<vector<int>>& grid,int n,int m, int t)\n {\n grid[x][y]=t;\n if(x>0 && grid[x-1][y]==1)\n {\n dfs(x-1,y,grid,n,m,t);\n }\n if(y>0 && grid[x][y-1]==1 )\n {\n dfs(x,y-1,grid,n,m,t);\n... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n int dx[4] ={1,-1,0,0};\n int dy[4] ={0,0,-1,1};\n\n void dfs(vector<vector<int>>& land,int x,int y,map<pair<int,int>,bool>&visited,int &localx, int &localy)\n {\n visited[{x,y}]=true;\n localx=max(localx,x);\n localy=max(localy,y);\n for(... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n int dx[4] ={1,-1,0,0};\n int dy[4] ={0,0,-1,1};\n\n void dfs(vector<vector<int>>& land,int x,int y,map<pair<int,int>,bool>&visited,int &localx, int &localy)\n {\n visited[{x,y}]=true;\n localx=max(localx,x);\n localy=max(localy,y);\n for(... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int row, int col, vector<vector<int>> &vis, int &r2, int &c2, \n vector<vector<int>> &land){\n vis[row][col]=1;\n vector<int> drow = {0, -1, 0, 1};\n vector<int> dcol = {-1, 0, 1, 0};\n int n = land.size();\n int m = land[0].size... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int row, int col, vector<vector<int>> &vis, int &r2, int &c2, \n vector<vector<int>> &land){\n vis[row][col]=1;\n vector<int> drow = {0, -1, 0, 1};\n vector<int> dcol = {-1, 0, 1, 0};\n int n = land.size();\n int m = land[0].size... |
2,103 | <p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>land</code> where a <code>0</code> represents a hectare of forested land and a <code>1</code> represents a hectare of farmland.</p>
<p>To keep the land organized, there are designated rectangular areas of hectares that consist <strong... | 3 | {
"code": "class Solution {\npublic:\n bool isValid(int r , int c, int numRows, int numCols){\n return (r >= 0 && c >= 0 && r < numRows && c < numCols);\n }\n\n void dfs(vector<vector<int>>& land, vector<vector<bool>>& visited, vector<int>& result, int r, int c, int numRows, int numCols){\n if ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.