id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n Solution() {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int rowCount = grid1.size();\n int colCount = grid1[0].size();\n static vector<int> parents(501 *... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n Solution() {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int rowCount = grid1.size();\n int colCount = grid1[0].size();\n static vector<int> parents(501 *... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n Solution() {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int rowCount = grid1.size();\n int colCount = grid1[0].size();\n static vector<int> parents(501 *... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int rowCount = grid1.size();\n int colCount = grid1[0].size();\n static vector<int> parents = vector<int>(501 * 501);\n // iota(parents.begin(), parents.end(), 0);\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int rowCount = grid1.size();\n int colCount = grid1[0].size();\n static vector<int> parents = vector<int>(501 * 501);\n // iota(parents.begin(), parents.end(), 0);\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n Solution() {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int rowCount = grid1.size();\n int colCount = grid1[0].size();\n static vector<int> parents(501 *... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n Solution() {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int rowCount = grid1.size();\n int colCount = grid1[0].size();\n // vector<int> parents(rowCount ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "#define NO_SAN __attribute__((no_sanitize(\"undefined\", \"address\", \"coverage\", \"thread\")))\n#define INL __attribute__((always_inline))\n\nclass Solution {\nprivate:\n static constexpr uint16_t MAXN = 500, MAXM = 500;\n static constexpr uint MAXS = MAXN * MAXM;\n\n static uint root[MAXS + 1u... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "#define NO_SAN __attribute__((no_sanitize(\"undefined\", \"address\", \"coverage\", \"thread\")))\n#define INL __attribute__((always_inline))\n\nclass Solution {\nprivate:\n static constexpr uint16_t MAXN = 500, MAXM = 500;\n static constexpr uint MAXS = MAXN * MAXM;\n\n static uint root[MAXS + 1u... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n // States 0 - Water, 1 - Untested Land, 3 - Tested Land (Temporarily Sub), 4 -\n // Tested Land (Not Sub)\n int recursiveDFS(vector<vector<int>> &grid1, vector<vector<int>> &grid2,\n int M, int N, int x, int y) {\n bool isSub = grid1[x][y] == 1;\n grid... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n int countSubIslands(std::vector<std::vector<int>>& grid1,\n std::vector<std::vector<int>>& grid2) {\n int n{ static_cast<int>(grid1.size()) };\n int m{ static_cast<int>(grid1[0].size()) };\n\n std::vector<std::pair<int, int>> queue;... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n\n vector<int> xx = {0, 1, 0, -1};\n vector<int> yy = {1, 0, -1, 0};\n\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n \n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n\n int ans = 0;\n int n = gr... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int n = grid1.size();\n int m = grid1[0].size();\n stack<pair<int, int>> s;\n int ans = 0;\n for(int i = 0; i < grid2.size(); ++i) {\n for(int j = 0; ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "template<typename F>\nvoid for_each_neigh(const int i, const int j, const int m, const int n, F f) {\n if (j > 0) {\n f(i, j - 1);\n }\n if (j + 1 < n) {\n f(i, j + 1);\n }\n if (i > 0) {\n f(i - 1, j);\n }\n if (i + 1 < m) {\n f(i + 1, j);\n }\n}\n\nclas... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int ind, ind2, x, y, n = grid1[0].size(), m = grid1.size(), answer = 0;\n pair<int, int> arr[m * n];\n bool b;\n for (int i = 0; i != m; ++i) {\n for (int j ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "#include <ranges>\n\ninline const auto optimize = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n static constexpr int countSubIslands(const std::vector<std::vector<int>>& grid1,\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "inline const auto optimize = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n static int countSubIslands(const std::vector<std::vector<int>>& grid1,\n const std::vector... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "inline const auto optimize = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n static int countSubIslands(const std::vector<std::vector<int>>& grid1,\n const std::vector... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n bool check(vector<vector<int>>& grid1,vector<vector<int>>& grid2,int i,int j){\n int r[4]={-1,0,0,1};\n int c[4]={0,-1,1,0};\n for(int ind=0;ind<4;ind++){\n int nr=i+r[ind];\n int nc=j+c[ind];\n if(nr<0 || nc<0 || nr==grid... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "inline const auto optimize = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n static int countSubIslands(const std::vector<std::vector<int>>& grid1,\n const std::vector... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "inline const auto optimize = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n static int countSubIslands(const std::vector<std::vector<int>>& grid1,\n const std::vector... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "inline const auto optimize = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n static int countSubIslands(const std::vector<std::vector<int>>& grid1,\n const std::vector... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "inline const auto optimize = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\n\nclass Solution {\npublic:\n static int countSubIslands(const std::vector<std::vector<int>>& grid1, const std::vector<std::vector<int>>& grid2) {\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "\n\nclass Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int sub_islands = 0;\n vector<std::pair<int,int>> indexes;\n vector<std::pair<int,int>> stack;\n std::pair<int, int> coord;\n\n for(int i = 0; i < grid1.size... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "int speedup = [] {ios::sync_with_stdio(0); cin.tie(0); return 0;}();\nchar grid[501*502];\nint step;\n\nbool check(char *p) {\n if (!(*p & 1)) return true;\n if (!(*p & 2)) return false;\n *p = 0;\n return check(p-step) & check(p-1) & check(p+1) & check(p+step);\n}\n\nclass Solution {\npublic:\... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "inline const auto optimize = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n static int countSubIslands(const std::vector<std::vector<int>>& grid1,\n const std::vector... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "inline const auto optimize = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\n\nclass Solution {\npublic:\n static int countSubIslands(const std::vector<std::vector<int>>& grid1, const std::vector<std::vector<int>>& grid2) {\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n // vector<vector<int>> visited; //needed for 1st and 2nd\n int w, h;\n\n // //first try\n // vector<vector<int>> getIsland(vector<vector<int>>& grid2, int m, int n){\n // queue<pair<int, int>> q;\n // q.push(make_pair(m, n));\n \n // vecto... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "inline const auto optimize = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\n\nclass Solution {\npublic:\n static int countSubIslands(const std::vector<std::vector<int>>& grid1, const std::vector<std::vector<int>>& grid2) {\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "inline const auto optimize = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\n\nclass Solution {\npublic:\n static int countSubIslands(const std::vector<std::vector<int>>& grid1, const std::vector<std::vector<int>>& grid2) {\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "#pragma GCC optimize (\"Ofast\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native\")\nstruct UnionFind {\n vector<int> parent, rank, isSubIsland;\n explicit UnionFind(int n) : parent(vector<int>(n)), rank(vector<int>(n, 1)), isSubIsland(vector<int>(n, true)) {\n i... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>>* gref1;\n vector<vector<int>>* gref2;\n bool isSub;\n void createIsland(int i, int j) {\n (*gref2)[i][j] = 0;\n if ((*gref1)[i][j] == 0) {\n isSub = false;\n }\n iterator(i+1, j);\n iterator(i-1, j);\n... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n void dfs(std::vector<std::vector<int>>& grid, int i, int j){\n int n = grid.size();\n int m = grid[0].size();\n if(i<0 || i>=n || j<0 || j>=m || grid[i][j] != 1){\n return;\n }\n grid[i][j] = 0;\n dfs(grid, i+1, j);\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int m = grid1.size(), n = grid1[0].size();\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n if (grid1[i][j] == 0 && grid2[i][j] == 1) {\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 1 | {
"code": "class Solution {\npublic:\nint n, m;\nint a[505][505];\nbool vis[505][505];\n bool ans= false;\n vector<pair<int, int>> v = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};\n\nbool isValid(int i, int j)\n{\n if (i >= 0 && i < n && j >= 0 && j < m )\n {\n return true;\n }\n\n else\n {\n ret... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 1 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int m = grid2.size(), n = grid2[0].size();\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n // if grid2 is land and grid1 isn't, invalidate... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 2 | {
"code": "class Solution \n{\n struct Node\n {\n bool vis = false;\n int val1;\n int val2;\n }node[500][500];\n int n, m;\n void DFS_Check(pair<int, int> node_id, bool& result)\n {\n node[node_id.first][node_id.second].vis = true;\n \n if(node[node_id.first... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 2 | {
"code": "int dx[] = { +1, -1, 0, 0};\nint dy[] = {0, 0, +1, -1};\n\nclass Solution {\n\n\npublic:\n\n int n, m;\n int a[500 + 10][500 + 10];\n int b[500 + 10][500 + 10];\n int vis[500 + 10][500 + 10];\n int ok = 0;\n\n\n bool isvalid(int x, int y)\n {\n if (x >= 0 && x < n && y >= 0 && y... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 2 | {
"code": "class Solution {\npublic:\n bool check(vector<vector<int>>&grid,vector<vector<int>>&visted,int i,int j)\n {\n if(grid[i][j]==1)\n {\n return false;\n }\n visted[i][j]=true;\n int left=true;\n int right=true;\n int down=true;\n int up=... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 2 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& grid,int i,int j,vector<vector<int>>& vis,int &flag){\n int drow[] = {-1,0,1,0};\n int dcol[] = {0,1,0,-1};\n int n = grid.size();\n int m = grid[0].size();\n if(vis[i][j] == 0){\n flag = 0;\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 2 | {
"code": "class Solution {\n void activateIsland(std::map<int, int>& stateMap, int island){\n int& ref = stateMap[island];\n if(ref <= 1) return;\n int state = stateMap[ref];\n while(state > 1) state = stateMap[state];\n stateMap[ref] = island;\n ref = state;\n }\n\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 2 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int m = grid1.size(), n = grid1[0].size();\n function<void(int, int)> dfs = [&](int i, int j){\n if(i < 0 || i >= m || j < 0 || j >= n || grid2[i][j] == 0)\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 2 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int m = grid1.size(), n = grid1[0].size();\n int ans = 0;\n int dirs[5] = {-1, 0, 1, 0, -1};\n function<int(int, int)> dfs = [&](int i, int j) {\n int ok = g... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 2 | {
"code": "class Solution {\nprivate:\n int rows, cols;\n bool isSubIsland(vector<vector<int>>& grid1, vector<vector<int>>& grid2, int row, int col){\n int adj[4][2] = { { -1, 0}, { 0, -1}, { 1, 0 }, { 0, 1} };\n bool isSub = true;\n if(grid1[row][col] != 1) isSub = false;\n for(auto... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 2 | {
"code": "class Solution {\npublic:\n\n const vector<int> diri = {1, -1, 0, 0};\n const vector<int> dirj = {0, 0, -1, 1};\n\n bool validCell(int row, int col, vector<vector<int> >& grid1, vector<vector<int> >& grid2, \n vector<vector<bool> >& vis) {\n\n return row >= 0 && row < grid1.size() &&... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 2 | {
"code": "class Solution {\npublic:\n vector<int> dx = {-1, 1, 0, 0};\n vector<int> dy = {0, 0, 1, -1};\n void dfs2(vector<vector<int>>& grid2, int row, int col, int n, int m, vector<vector<int>>& vis2) {\n vis2[row][col] = 1;\n for (int i = 0; i < 4; i++) {\n int newrow = row + dx[... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>>dir = {{-1,0},{1,0},{0,-1},{0,1}};\n void dfs(vector<vector<int>>& grid1, vector<vector<int>>& grid2,int i,int j,int m,int n,\n vector<vector<bool>>& visited,bool &flag){\n visited[i][j] = true;\n\n for(int k=0;k<4;k++){\n int... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>>dir = {{-1,0},{1,0},{0,-1},{0,1}};\n void dfs(vector<vector<int>>& grid1, vector<vector<int>>& grid2,int i,int j,int m,int n,\n vector<vector<bool>>& visited,bool &flag){\n visited[i][j] = true;\n\n for(int k=0;k<4;k++){\n int... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int m = grid1.size();\n int n = grid1[0].size();\n int ans = 0;\n\n auto dfs = [&](int i, int j, auto&& dfs_ref) -> int {\n static vector<pair<int, int>> dir... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int n = grid1.size(), m = grid1[0].size();\n using ii = pair<int, int>;\n vector<vector<int>> vis(n, vector<int>(m, 0));\n vector<ii> dirs = {{0, 1}, {0, -1}, {1, 0}, {... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int m = grid1.size();\n int n = grid1[0].size();\n \n vector<vector<bool>> visited(m, vector<bool>(n, false));\n \n // in function call, where the return ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int m = grid1.size(), n = grid1[0].size();\n vector<vector<bool>> vis(m, vector<bool>(n, 0));\n\n int ans = 0;\n for (int i = 0; i < m; ++i) {\n for (int j =... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n\n void dfs(int i, int j,vector<vector<int>>& grid,vector<vector<bool>>& vis){\n if(grid[i][j]==0){\n return;\n }\n vis[i][j]=true;\n if(i-1>=0 && vis[i-1][j]==false){\n dfs(i-1,j,grid,vis);\n }\n if(j-1>=0 && vis... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\nprivate:\n int row, col;\n vector<pair<int, int>> directions = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};\n void dfs(const vector<vector<int>>& grid, vector<vector<bool>>& visited, int r, int c, vector<pair<int, int>>& cells) {\n if (r<0||r>=row||c<0||c>=col||visited[r][c]||grid[... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\nvoid dfs(int i,int j,vector<vector<int>>&grid2,vector<pair<int,int>>&ans,vector<vector<int>>&visit)\n{\n if(i>=grid2.size()||j>=grid2[0].size()||i<0||j<0||visit[i][j]==1)return;\n if(grid2[i][j]==0)return;\n visit[i][j]=1;\n ans.push_back({i,j});\n dfs(i+1,j,grid2,... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "#pragma GCC optimize (\"Ofast\")\n#pragma GCC target (\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx\")\n#pragma GCC optimize (\"-ffloat-store\")\n#pragma GCC optimize (\"O3\", \"unroll-loops\")\n\nauto init = []() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\n\n\ncl... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "#include <vector>\n#include <execution>\n#pragma GCC optimize(\"Ofast,unroll-loops\")\n#pragma GCC optimize (-Ofast, -flto, -ffast-math, -march=native, -mtune=native)\n#pragma GCC optimize(\"03\")\n#pragma GCC target (\"avx\")\n\nclass Island {\npublic:\n\tinline bool isSubIsland(const std::vector<std::vec... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int subIslands = 0;\n\n int rowSize = grid2.size();\n int colSize = grid2[0].size();\n\n vector<vector<bool>> visited(rowSize, vector<bool>(colSize, false));\n\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int subIslands = 0;\n\n int rowSize = grid2.size();\n int colSize = grid2[0].size();\n\n vector<vector<bool>> visited(rowSize, vector<bool>(colSize, false));\n\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class UnionFind {\npublic:\n UnionFind(int size)\n {\n m_data.resize(size, -1);\n m_children_count.resize(size, 0);\n }\n\n void merge(int idx0, int idx1)\n {\n auto u0 = get_union(idx0);\n auto u1 = get_union(idx1);\n if (u0 != u1)\n {\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class UnionFind {\npublic:\n UnionFind(int size)\n {\n m_data.resize(size, -1);\n m_children_count.resize(size, 0);\n }\n\n void merge(int idx0, int idx1)\n {\n auto u0 = get_union(idx0);\n auto u1 = get_union(idx1);\n if (u0 != u1)\n {\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<int>>&grid2,vector<vector<bool>>&visited,int i,int j,vector<pair<int,int>>&travelled){\n\n visited[i][j]=true;\n travelled.push_back({i,j});\n\n if(i+1<grid2.size() && visited[i+1][j]==false && grid2[i+1][j]==1){\n\n so... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n vector<vector< pair<int, int> >> subIslands;\n vector<vector<int>> visited (grid2.size(), vector<int> (grid2[0].size(), 0));\n\n // for(int i = 0; i < grid2.size(); i++)\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\nvoid dfs(vector<vector<int>>& grid, int x, int y, vector<pair<int, int>>& island) {\n // Check boundaries and if the current cell is water (0)\n if (x < 0 || y < 0 || x >= grid.size() || y >= grid[0].size() || grid[x][y] == 0)\n return;\n\n // Mark the cell as vis... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int i,int j,vector<vector<int>>& grid1, vector<vector<int>>& grid2,int &flag){\n if(grid1[i][j]==0) flag=1;\n grid2[i][j]=0;\n vector<pair<int,int>>dir={{-1,0},{1,0},{0,1},{0,-1}};\n for(int k=0;k<4;k++){\n int newi=i+dir[k].fir... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n bool dfs(int i,int j,int n,int m,vector<vector<int>>& grid1, vector<vector<int>>& grid2)\n {\n if(grid1[i][j]!=1)\n return 0;\n vector<int>dx={-1,1,0,0};\n vector<int>dy={0,0,1,-1};\n grid2[i][j]=0; bool x=1;\n for(int k=0;k<4;k++)... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "// DFS Approach.\n// T.C. == S.C. -> O(M * N).\n\nclass Solution {\npublic:\n // Boolean Variable For Sub - Island.\n bool island = false;\n\n void dfs(int row, int col, vector<vector<int>> &grid1, vector<vector<int>> &grid2) {\n\n int m = grid2.size(), n = grid2[0].size();\n\n // Ba... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int rowCount = grid1.size();\n int colCount = grid1[0].size();\n vector<int> parents = vector<int>(501 * 501);\n // iota(parents.begin(), parents.end(), 0);\n //... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n vector<bool> is_sub(mark(grid2), true);\n for (auto row = 0; row < grid2.size(); ++row) {\n for (auto col = 0; col < grid2[row].size(); ++col) {\n is_sub[gr... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n bool solve(vector<vector<int>>& a, vector<vector<int>>& b, vector<vector<int>>& vis, int i, int j) {\n int n = a.size();\n int m = a[0].size();\n \n // Base condition: out of bounds or water cell in b\n if (i < 0 || i >= n || j < 0 || j >= m... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<int>>& grid1, vector<vector<int>>& grid2, vector<vector<int>>& visited, bool& res, int i, int j, int n, int m){\n visited[i][j]=1;\n vector<pair<int,int>> dir = {{0,-1},{-1,0},{0,1},{1,0}};\n\n for(auto d: dir){\n int x... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "typedef unsigned long Coordinate;\n\nclass Solution {\npublic:\n inline unsigned short get_row(Coordinate coord)\n {\n return static_cast<unsigned short>((coord & 0xffff0000) >> sizeof(unsigned short) * 8);\n }\n\n inline unsigned short get_col(Coordinate coord)\n {\n return st... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "#include <vector>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int m = grid1.size();\n int n = grid1[0].size();\n vector<vector<bool>> visited(m, vector<bool>(n, false));\n \n aut... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n function<bool(int, int)> valid = [&](int x, int n) -> bool {\n return x >= 0 && x < n;\n };\n int n = size(grid1), m = size(grid1[0]);\n bool bad = 0;\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n function<bool(int, int)> valid = [&](int x, int n) -> bool {\n return x >= 0 && x < n;\n };\n int n = size(grid1), m = size(grid1[0]);\n bool bad = 0;\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int flag=1;\n\n void dfs(vector<vector<int>>& grid1, vector<vector<int>>& grid2,int i,int j)\n {\n int row=grid1.size();\n int col=grid1[0].size();\n if(grid2[i][j]!=grid1[i][j])\n {\n flag=1;\n }\n grid2[i][j]=0;\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int flag=1;\n\n void dfs(vector<vector<int>>& grid1, vector<vector<int>>& grid2,int i,int j)\n {\n int row=grid1.size();\n int col=grid1[0].size();\n if(grid2[i][j]!=grid1[i][j])\n {\n flag=1;\n }\n grid2[i][j]=0;\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& grid2,int x,int y,vector<vector<int>>&vis,\n set<pair<int,int>>&us){\n int m=grid2.size();\n int n=grid2[0].size();\n vis[x][y]=1;\n us.insert({x,y});\n int dx[... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int n = grid1.size();\n int m = grid1[0].size();\n for(int i = 0; i <= n * m; i++){\n parent[i] = i;\n }\n for(int i = 0; i < n; i++){\n fo... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int i,int j,vector<vector<int>>& grid1,vector<vector<int>>&grid2,int &c,vector<vector<int>>&vis){\n vis[i][j]=1;\n if(grid1[i][j]!=grid2[i][j]){\n c=0;\n }\n vector<int>x={-1,0,1,0};\n vector<int>y={0,1,0,-1};\n fo... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\n private:\n void dfs(vector<vector<int>>& grid1, vector<vector<int>>& grid2,vector<vector<int>>&visited ,int row,int col,bool &sub){\n if(grid1[row][col]!=1) sub = false;\n visited[row][col]=1;\n vector<int> drow = {-1,1,0,0};\n vector<int> dcol = {0,0,-1... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int dfs(int r,int c,vector<vector<int>> &grid1, vector<vector<int>>&grid2, vector<vector<int>> &vis)\n {\n int n=grid2.size();\n int m=grid2[0].size();\n\n bool isSubIsLand = true;\n\n if(grid1[r][c]==0)\n {\n isSubIsLand= fals... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n bool DFS(int row,int col,vector<vector<int>>& grid1, vector<vector<int>>& grid2,vector<vector<int>>& vis){\n int n=vis.size();\n int m=vis[0].size();\n vis[row][col]=1;\n bool ans=true;\n if(grid1[row][col]==0) ans=false;\n vector<in... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n bool flood(int x, int y, vector<vector<int>>& grid1, vector<vector<int>>& grid2, vector<vector<bool>>& visited){\n //if( visited[x][y] ) return true;\n visited[x][y] = true;\n bool ans = true;\n if(grid1[x][y] ==0) ans = false;\n vector<int>... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n bool helper(int i,int j,vector<vector<int>>& grid1, vector<vector<int>>& grid2,vector<vector<bool>>&visited){\n cout<<i<<\" \"<<j<<endl;\n int m=grid1.size();\n int n=grid1[0].size();\n visited[i][j]=1;\n vector<int>v1={0,1,0,-1};\n v... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n bool find(int i, int j, vector<vector<int>>& g1, vector<vector<int>>& g2, vector<vector<int>> &visit, int n, int m){\n visit[i][j]=1;\n vector<int>row = {1,0,-1,0};\n vector<int>col = {0,1,0,-1};\n bool sts =true;\n for(int k=0;k<4;k++) {\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class DisjointSet{\n public:\n vector<int> size,parent;\n DisjointSet(int n){\n size.resize(n);\n parent.resize(n);\n for(int i=0;i<n;i++){\n parent[i]=i;\n size[i]=1;\n }\n }\n\n int findUparent(int node){\n if(node==parent[node]){\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int res = 0;\n const int r = grid2.size();\n const int c = grid2[0].size();\n for (int i = 0; i < r; ++i) {\n for (int j = 0; j < c; ++j) {\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n#define VAILD(x, y, m, n) (x >= 0 && x < m && y >= 0 && y < n)\n int dirs[5] = {0, 1, 0, -1, 0};\n void dfs(vector<vector<int>>& grid, int i, int j, vector<vector<int>> &land) {\n land.push_back({i, j});\n grid[i][j] = 0;\n int m = grid.size(), n = grid... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "#define REP(i, n) for(int i = 0; i < n; i++)\n#define REPP(i, n) for(int i = 1; i <= n; i++)\n#define ALL(obj) (obj).begin(), (obj).end()\n\nclass Solution {\nprivate:\n int m, n;\n vector<int> dx, dy;\n vector<vector<int>> grid1, grid2, board1;\n vector<vector<bool>> visited;\n vector<vector<pair<int... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n\n void f(int i, int j, int n, int m, vector<vector<int>>& grid1, vector<vector<int>>& grid2, vector<vector<int>>& vis, vector<pair<int, int>>& temp){\n vis[i][j] = 1;\n vector<int> dx = {-1, 1, 0, 0};\n vector<int> dy = {0, 0, -1, 1};\n bool flag =... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n int m=grid1.size(); int n=grid1[0].size();\n vector<vector<int>> v(m , vector<int>(n,0));\n queue<vector<int>> q;\n vector<vector<pair<int,int>>> islands;\n for(... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int i,int j,vector<vector<int>> &vis,bool &issubisland,vector<vector<int>>& grid1, vector<vector<int>>& grid2,vector<int> row,vector<int> col,int m,int n){\n vis[i][j]=1;\n if(grid2[i][j]!=grid1[i][j]) issubisland=false;\n for(int k=0;k<4;k++){\n... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int r, int c, vector<pair<int, int>> &curr, vector<vector<int>>& grid2, vector<vector<bool>> &vis){\n if(r<0 || c<0 || r>=grid2.size() || c>=grid2[0].size() || grid2[r][c]==0 || vis[r][c])\n return;\n \n curr.push_back({r, c});\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\n bool isSubIsland(vector<vector<int>>& grid1, vector<vector<int>>& grid2, int i, int j){\n int m = grid2.size(), n = grid2[0].size();\n if(i < 0 or i >= m or j < 0 or j >= n or grid2[i][j] != 1)\n return true;\n \n if(grid1[i][j] != grid2[i][j])\n... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int i,int j,vector<vector<int>>&grid2,vector<vector<int>>&vis,vector<pair<int,int>>&v){\n vis[i][j]=1;\n v.push_back({i,j});\n vector<int>dx={1,-1,0,0};\n vector<int>dy={0,0,-1,1};\n for(int k=0;k<4;k++){\n int nx=i+dx[k]... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic:\n int neighb[4][2] = {{-1,0}, {0,1}, {1,0}, {0,-1}};\n void dfs(int i, int j, vector<vector<int>> &grid, vector<vector<bool>> &visited, vector<vector<int>> &temp){\n visited[i][j] = true;\n temp.push_back({i,j});\n for(auto n : neighb){\n int ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\npublic: \n vector<vector<int>> dir = {{-1,0},{1,0},{0,1},{0,-1}};\n bool dfs(vector<vector<int>>& grid1,vector<vector<int>>& grid2,int i,int j,int n,int m){\n if(grid1[i][j]!=1){\n return false;\n }\n grid2[i][j]=0;\n bool ans = true;\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "class Solution {\n vector<vector<int>> dir={{-1,0},{1,0},{0,-1},{0,1}};\n bool isvalid(int i,int j,int n,int m){\n return (i>=0&&i<n&&j>=0&&j<m);\n }\n bool dfs(int i,int j,int n,int m,vector<vector<int>>& grid1, vector<vector<int>>& grid2){\n if(grid2[i][j]==1 && grid1[i][j]==0) re... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 3 | {
"code": "\nint dx[4]={1,-1,0,0};\nint dy[4]={0,0,1,-1};\n\nbool dfs(int row, int col, vector<vector<int>>& grid1, vector<vector<int>>& grid2, map<pair<int,int>,int>&vis){\n vis[make_pair(row,col)]=1;\nbool c=true;\nfor(int i=0;i<4;i++){\n int nx=row+dx[i];\n int ny=col+dy[i];\n if(nx>=0&&ny>=0&&nx<grid1... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.