id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n string temp=\"\";\n\n for(int i=0;i<s.length();i++){\n temp+=s[i];\n int j=i+1;\n bool flag=true;\n while(j<s.length()){\n int b=temp.length();\n ... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n string sub;\n for (int i = 0; i < s.size() - 1; ++i) {\n sub += s[i];\n bool flag = true;\n for (int j = i + 1; j < s.size(); j += sub.size()) {\n if (sub != s.substr(j, sub.size())) {\n flag = fal... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n for(int i=1; i<=s.size()/2; ++i){\n string sub = s.substr(0, i);\n string newstr;\n while(newstr.size()<s.size()){\n newstr+=sub;\n }\n if(newstr == s) ret... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n\n // queue<int> q;\n\n // for(int i=0;i<s.size();i++){\n // if(s[i]!=q.front()){\n // q.push(s[i]);\n // }\n // else{\n ... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool sysmetric(string s) {\n return string(s.begin(), s.begin() + s.size() / 2) == string(s.begin() + s.size() / 2, s.end());\n }\n bool repeatedSubstringPattern(string s) {\n if(sysmetric(s)) return true;\n for(int i = 1; i <= s.length() / 3; i++) ... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n=s.length();\n // if(n%2) return false;\n \n vector<string>vec;\n string tmp;\n // all possible substring patterns, 1st letter vala char toh always include krna hoga, else bich mein se ... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int i=1;\n int t=i;\n while(i<=s.size()/2){\n if (s.substr(0,i)==s.substr(t,i)){\n if (t+i==s.size()) return true;\n t=t+i;\n continue;\n }\n ... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n // sliding window approach\n\n int w = 1;\n int max_size = s.size() / 2;\n while(w <= max_size)\n {\n // std::cout << w << \" \" << max_size << endl;\n for(int i = 0; i+w <= s... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(std::string s) {\n int len = s.size();\n int j {1};\n int counter {0};\n while (j < (len / 2) + 1){\n \n for(int i {0}; i < len ; i = i + j){\n // std::cout<< \"s.substr(\" << i << ... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool solve(string s1, string s2){\n int i = 0, j = 0;\n string str = \"\";\n while(str.size() < s2.size()){\n str+= s1;\n }\n if(str == s2){\n return true;\n }\n else{\n return false;\n }... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(std::string s) {\n \n int j {1};\n int counter {0};\n while (j < s.size() + 1){\n \n for(int i {0}; i < s.size(); i = i + j){\n // std::cout<< \"s.substr(\" << i << \" , \" << j << ... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.length();\n\n string ss = s.substr(1, n - 1) + s[0];\n for(int i=0;i<n/2;i++){\n if(ss == s)\n return true;\n ss = ss.substr(1, n - 1) + ss[0];\n }\n\n ... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int size = s.size();\n for (int i = 1; i < size; i++) {\n string sub = s.substr(0,i);\n int size2 = sub.size();\n string fullstring;\n for (int j = 0; j < size; j += size2 ) ... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatPattern(string& pattern, string& s) {\n string repeated;\n while (repeated.size() < s.size()) {\n repeated += pattern;\n }\n return repeated == s;\n }\n\n bool repeatedSubstringPattern(string s) {\n for (int i = 1... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n for(int i=1;i<s.length();i++){\n string substr=s.substr(0,i);\n string str=substr;\n while(str.length()<s.length()){\n str+=substr;\n }\n if(str==s){ \n ... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s)\n {\n for (int i = 1 ; i <= s.length() / 2; i++)\n {\n string temp = s.substr(i) + s.substr(0, i);\n if (s == temp)\n return true;\n }\n return false;\n }\n};",
"m... |
459 | <p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abab"
<strong>Output:</strong> true
<strong>Explanatio... | 3 | {
"code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s)\n {\n for (int i = 1 ; i <= s.length() / 2; i++)\n {\n string temp = s.substr(i) + s.substr(0, i);\n if (s == temp)\n return true;\n }\n return false;\n }\n};",
"m... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 0 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) \n {\n int r=grid.size();\n int c=grid[0].size();\n int co=0;\n int row[4]={-1,0,1,0};\n int col[4]={0,-1,0,1};\n //int rn=0,cn=0;\n for(int i=0;i<r;i++)\n {\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 0 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n int n = grid.size();\n\n int ans = 0;\n for(int i = 0; i < n; i++){\n for(int j = 0; j < grid[i].size(); j++){\n if(grid[i][j] == 1){\n if(i == 0) ans++; // if... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 1 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) \n {\n int r=grid.size();\n int c=grid[0].size();\n int co=0;\n int row[4]={-1,0,1,0};\n int col[4]={0,-1,0,1};\n //int rn=0,cn=0;\n for(int i=0;i<r;i++)\n {\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 1 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n int islands = 0;\n int neighbors = 0;\n\n for (int i = 0; i < grid.size(); ++i) {\n for (int j = 0; j < grid[0].size(); ++j) {\n if (grid[i][j] == 1) {\n islan... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n\n\n\n\n vector<pair<int,int>> directions ={{1,0},{-1,0},{0,1},{0,-1}};\n int result=0;\n\n for(int i=0;i<grid.size();i++)\n {\n for(int j=0;j<grid[0].size();j++)\n {\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int dfs(int row, int column, vector<vector<int>>& grid, int ans){\n if(row < 0 || column < 0 || row >= grid.size() || column >=grid[0].size() || grid[row][column] == 0){\n return 1;\n }\n if(grid[row][column] == -1){\n return 0;\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n\n\n\n\n vector<pair<int,int>> directions ={{1,0},{-1,0},{0,1},{0,-1}};\n int result=0;\n\n for(int i=0;i<grid.size();i++)\n {\n for(int j=0;j<grid[0].size();j++)\n {\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int dfs(vector<vector<int>>& grid, int r, int c, int p) {\n if (r < 0 || c < 0 || r >= grid.size() || c >= grid[0].size() || grid[r][c] == 0) return 1;\n if (grid[r][c] == -1) return 0;\n grid[r][c] = -1;\n p = dfs(grid, r + 1, c, p);\n p +=... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int m;\n int n;\n int perimeter;\n void dfs(vector<vector<int>>& grid, int i, int j){\n if(i<0 ||i>=m || j<0 ||j>=n || grid[i][j]==0) {//out of bound or if water present\n perimeter++;\n return;//imp or else wont go to the next possibilit... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int n;\n int m;\n int peri;\n \n void DFS(vector<vector<int>>& grid,int i,int j)\n {\n if(i<0||i>=m||j<0||j>=n||grid[i][j]==0)\n {\n peri++;\n return;\n }\n if(grid[i][j]==-1)\n {\n return;\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n\n void dfs(vector<vector<int>>& grid,int i,int row,int j,int col,int &ans)\n {\n // Out of bounds or water cell, count as part of the perimeter\n if (i < 0 || j < 0 || i >= row || j >= col || grid[i][j] == 0) {\n ans++;\n return;\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n m = grid.size();\n n = grid.front().size();\n ans = 0;\n for (int ii = 0; ii < m; ++ii) {\n for (int jj = 0; jj < n; ++jj) {\n if (grid[ii][jj]==1) dfs(grid, ii, jj);\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int sum;\n bool check(vector<vector<int>>& grid, int i, int j){\n if(i>-1 && i<grid.size() && j >-1 &&j<grid[0].size() && grid[i][j]==1)\n return true;\n return false;\n \n }\n \n bool check2(vector<vector<int>>& grid, int i, int... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\nprivate:\n int ans = 0, row, col;\n int dir[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};\n bool vis[100][100] = {false};\n\n bool isValid(int i, int j) {\n return i >= 0 && i < row && j >= 0 && j < col;\n }\n int dfs(int si, int sj, vector<vector<int>>& grid) {\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n void visitisland(vector<vector<int>>& grid,int r,int c,int row,int col,int *peri)\n {\n\n if(r >= row || c >= col || r<0 || c < 0 ||grid[r][c]!=1)\n return;\n\n grid[r][c] = 2;\n\n *peri += (r-1 < 0 || grid[r-1][c] == 0) +\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n bool vis[105][1005];\n int ans = 0;\n int n,m;\n vector<pair<int,int>> d={{0,1},{0,-1},{1,0},{-1,0}};\n bool valid(int ci, int cj)\n {\n return ci >= 0 && ci < n && cj >= 0 && cj < m;\n }\n void dfs(int si, int sj, vector<vector<int>> &grid)\n {... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\nprivate:\n int directions[4][2] = {{-1,0},{1, 0},{0,-1},{0,1}};\n void dfs(vector<vector<int>>& grid, int i, int j, int &primeter ){\n grid[i][j] = -1;\n for (auto [di, dj]: directions){\n if (i+di<0 || i+di>= grid.size() || j+dj<0 || j+dj>=grid[0].size() ||... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n int a = 0, d = 0;\n int f[105][105] = {0};\n for(int i = 0; i < grid.size(); i++)\n {\n for(int j = 0; j < grid[i].size(); j++)\n {\n if(grid[i][j] == 1)\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int perimeter = 0;\n // vector<vector<bool>> vis(100 , vector<bool>(100 , false));\n int vis[100][100] = {false};\n vector<int> delrow = {-1, 0 ,1 , 0};\n vector<int> delcol = {0 , 1 , 0 , -1};\n\n void dfs(int row , int col , vector<vector<int>>& grid){\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n bool vis[200][200];\n int cnt;\n int r,c;\n vector<pair<int,int>> d = {{1,0},{0,1},{-1,0},{0,-1}};\n bool valid(int ci, int cj)\n {\n if(ci>=r || ci<0 || cj>=c || cj<0)\n {\n return false;\n }\n return true;\n }\n\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\nint ans=0;\nvector<pair<int,int>>idx = {{-1,0}, {0,-1}, {1,0}, {0,1}};\nvoid dfs(vector<vector<int>>& grid, int i, int j){\n grid[i][j]=-1;\n ans+=4;\n for(int k=0;k<idx.size();k++){\n int x = i+idx[k].first;\n int y = j+idx[k].second;\n cout<<x<<\" ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\nprivate:\n int m;\n int n;\n vector< vector<int>> directions = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\npublic:\n int find_boundary(vector<vector<int>>& grid, int i, int j){\n int cells = 0;\n // if(i>0 && grid[i-1][j] == 1){\n // cells++;\n // }\n\... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int n, m;\n int vis[105][105];\n int cnt;\n vector<pair<int, int>> d = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};\n bool valid(int i, int j) { return (i >= 0 && i < n && j >= 0 && j < m); }\n void dfs(int si, int sj, vector<vector<int>>& grid){\n vis[si][sj] = ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int vis[105][105];\n int ans;\n vector<pair<int, int>> d = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};\n int n, m;\n bool valid(int ci, int cj) {\n if (ci >= 0 && ci < n && cj >= 0 && cj < m)\n return true;\n else\n return false;\n }... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int n,m;\n bool vis[105][105];\n int ans = 0;\n vector<pair<int,int>> d={{1,0},{-1,0},{0,1},{0,-1}};\n bool valid(int i, int j)\n {\n return i >= 0 && i < n && j >= 0 && j < m;\n }\n void dfs(int si, int sj, vector<vector<int>> &grid)\n {\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\nbool vis[105][105];\nint ans;\nvector<pair<int,int>>d= {{0,1},{0,-1},{1,0},{-1,0}};\nint n, m;\nbool valid(int ci,int cj)\n{\n if(ci>=0 && ci<n && cj>=0 && cj<m) return true;\n else return false;\n}\nvoid dfs(int si, int sj, vector<vector<int>>& grid)\n{\n vis[si][sj]=true;... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution {\npublic:\n int row,col,perimeter;\n bool vis[100][100];\n vector<pair<int,int>>d={{0,-1},{0,1},{-1,0},{1,0}};\n\n bool valid(int i,int j){\n return 0<=i&&i<row&&0<=j&&j<col;\n }\n\n void dfs(int i,int j,vector<vector<int>>&grid){\n vis[i][j]=true;\n f... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 2 | {
"code": "class Solution\n{\n public:\n bool vis[105][105];\n int ans;\n vector<pair<int,int>> d={{0,1},{0,-1},{-1,0},{1,0}};\n int n,m;\n bool valid(int ci, int cj)\n {\n if(ci>=0 && ci<n && cj>=0 && cj<m) return true;\n else return false;\n }\n void dfs(int si, int sj,vecto... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n if (grid.size() == 0)\n return 0;\n\n int rows = grid.size();\n int cols = grid[0].size();\n int perimeter = 0;\n vector<vector<bool>> visit(rows, vector<bool>(cols, false));\n\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>>value{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n int func(vector<vector<int>>& grid, int i, int j) {\n if (i < 0 || j < 0 || i == grid.size() || j == grid[0].size() || grid[i][j] == 0 || grid[i][j] == 2) return 0;\n int ans = 0;\n if (i-1 ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size(), res = 0;\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n if (grid[i][j] == 1) {\n grid[i][j] = 2;\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int n,m;\n int dfs(int i,int j,vector<vector<int>> & grid,vector<vector<bool>> & visited){\n if (i < 0 || j < 0 || i >= n || j >= m || grid[i][j] == 0) {\n return 1;\n }\n if(visited[i][j]){\n return 0;\n }\n visit... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\n\n int dfs(int i,int j,vector<vector<int>>& grid,vector<vector<bool>>& vis){\n // For boundry of grid or water neighbour we return 1\n if(i<0 or i>=grid.size() or j<0 or j>=grid[0].size() or grid[i][j] == 0) return 1 ;\n if(vis[i][j]) return 0;\n vis[i][j] =... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\n int rows;\n int cols;\n int perimeter = 0;\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n rows = grid.size();\n cols = grid[0].size();\n\n // We only need to find the first land cell and explore the entire island\n for (int i = 0; i ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n // dfs\n // hit water or a border, add 1\n int perim = 0;\n vector<vector<bool>> visited(grid.size(), vector<bool>(grid[0].size()));\n for(int i = 0; i < grid.size(); i++)\n {\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n\n int dfs(vector<vector<int>>& grid,vector<vector<bool>> &visited,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]==0){\n return 1;\n }\n if(visited[i][j]){\n retu... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\n \n vector<vector<bool>> vis;\n public:\n int dfs(vector<vector<int>> &grid,int i, int j){\n if(i>=grid.size() || j>=grid[0].size()|| i<0|| j<0 ||grid[i][j] == 0)\n return 1;\n\n if(vis[i][j]){\n return 0;\n \n }\n vis[i][j]=tr... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int row[4] = {-1,1,0,0};\n int col[4] = {0,0,1,-1};\n int ans = 0;\n int dfs(vector<vector<int>>&grid,vector<vector<bool>>&vis,int i,int j){\n if(i<0 || i>=grid.size() || j<0 || j>=grid[0].size() || grid[i][j] == 0)\n return 1;\n if(vis[i][j]... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<bool>>&visited,vector<vector<int>>& grid,int row,int col,int&count){\n\n visited[row][col] = true;\n\n int drow[] = {-1,0,1,0};\n int dcol[] = {0,1,0,-1};\n\n for(int i = 0;i<4;i++){\n int nrow = row + drow[i];\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int c=0;\n int check(vector<vector<int>>& v,vector<vector<int>>& vis,int i,int j)\n {\n\n if(i<0 || i>=v.size() || j<0 || j>=v[0].size() || v[i][j]==0) return 1;\n if(vis[i][j]) return 0;\n vis[i][j]=1;\n int p=check(v,vis,i+1,j);\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> v;\n vector<pair<int, int>> chk = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n bool vis[500][500];\n int per = 0;\n int row, col;\n\n int islandPerimeter(vector<vector<int>>& grid) {\n v = grid;\n memset(vis, false, sizeof(vis));\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\nint cnt=0;\n void dfs( int i,int j, vector<vector<int>>& grid, vector<vector< int>>& vis){\n int n= grid.size();\n int m= grid[0].size();\n if(i<0 || i>=n || j<0 || j>=m || grid[i][j]==0){cnt++; return ;}\n\n if(vis[i][j]==1) return;\n\n vis[i][j]=1;\n dfs( i-1,j, grid, vi... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int dx[4] = { 1,-1,0,0 };\n int dy[4] = { 0,0,1,-1 };\npublic:\n //创建dfs函数\n void dfs(vector<vector<int>>& grid, vector<vector<int>>& used, int& result, int row, int col) {\n //将当前岛屿标记为使用\n used[row][col] = 1;\n //初始化当前岛屿的周长\n int temp = 4... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\nprivate:\n void dfs(int row, int col, int &ans, vector<vector<int>>& grid, vector<vector<int>>& vis) {\n int n = grid.size();\n int m = grid[0].size();\n vis[row][col] = 1; // Mark as visited\n\n int delrow[] = {0, 1, 0, -1};\n int delcol[] = {-1, 0,... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\nprivate:\n void dfs(int row, int col, int &ans, vector<vector<int>>& grid, vector<vector<int>>& vis) {\n int n = grid.size();\n int m = grid[0].size();\n vis[row][col] = 1; // Mark as visited\n\n int delrow[] = {0, 1, 0, -1};\n int delcol[] = {-1, 0,... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int perimeter = 0;\n // vector<vector<bool>> vis(100 , vector<bool>(100 , false));\n vector<int> delrow = {-1, 0 ,1 , 0};\n vector<int> delcol = {0 , 1 , 0 , -1};\n\n void dfs(int row , int col , vector<vector<int>>& grid , vector<vector<bool>>& vis){\n vis... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int perimeter = 0;\n // vector<vector<bool>> vis(100 , vector<bool>(100 , false));\n vector<int> delrow = {-1, 0 ,1 , 0};\n vector<int> delcol = {0 , 1 , 0 , -1};\n\n void dfs(int row , int col , vector<vector<int>>& grid , vector<vector<bool>>& vis){\n vis... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\n vector<int>dx={0,1,0,-1,0};\npublic:\n bool isValid(int i,int j,int n,int m){\n return i>=0 && j>=0 && i<n && j<m;\n }\n int dfs(int i,int j,vector<vector<int>>& grid,vector<vector<int>>& vis,int n,int m){\n if(!isValid(i,j,n,m))return 0;\n if(vis[i][j] |... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\nprivate:\n void dfs(vector<vector<int>>& grid, vector<vector<int>>& visited, int row, int col,\n int delRow[], int delCol[], int& count) {\n visited[row][col] = 1;\n int n = grid.size();\n int m = grid[0].size();\n\n for (int i = 0; i < 4; i++) {... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int n, m;\n bool valid(int ci, int cj, int n, int m) {\n if (ci < 0 || ci >= n || cj < 0 || cj >= m)\n return false;\n return true;\n }\n int islandPerimeter(vector<vector<int>>& grid) {\n int cnt = 0;\n int n = grid.size();\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int n, m;\n bool valid(int ci, int cj) {\n if (ci < 0 || ci >= n || cj < 0 || cj >= m)\n return false;\n return true;\n }\n int islandPerimeter(vector<vector<int>>& grid) {\n int cnt = 0;\n n = grid.size();\n m = grid[0]... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int p =0;\n void fun(vector<vector<int>>& grid,int i,int j,vector<vector<int>>& visited)\n {\n if(i<0 || j<0 || i>grid.size()-1 || j>grid[0].size()-1|| grid[i][j]==0)\n {\n p++;\n return;\n } \n if(visited[i][j]==1)\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\n int visited[101][101] = {0};\n vector<vector<int>> g;\npublic:\n int per = 0;\n int X = 0, Y = 0;\n\n int getGrid(int x, int y)\n {\n if (x < 0 || y < 0 || x >= X || y>=Y )\n return 0;\n else\n return g[y][ x];\n }\n void searc... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n // find the land by iterating across the grid until finding a 1\n // Add the first piece of land on to a queue\n // Track the visited nodes by turning visited nodes to 2\n\n\n // Find the land\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> gGrid;\n bool visited[101][101];\n int dr[4] = {1, 0, -1, 0};\n int dc[4] = {0, 1, 0, -1};\n bool isValid(int r, int c) {\n if (r < 0 || r >= gGrid.size() || c < 0 || c >= gGrid[r].size()) return false;\n return true;\n }\n\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "int dir[][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n\nclass Solution {\npublic:\n int expand(queue<pair<int, int>>& bfs, vector<vector<int>>& grid) {\n int perimeter = 0;\n while (!bfs.empty()) {\n auto cur = bfs.front();\n bfs.pop();\n\n if (grid[cur.first... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n int rows = grid.size();\n int cols = grid[0].size();\n int ans = 0;\n queue<pair<int, int>> q;\n\n for (int i = 0; i < rows; i++) {\n for (int j = 0; j < cols; j++) {\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\nvector<vector<int>> df{{1,0},{-1,0},{0,1},{0,-1}};\n int dfs(vector<vector<int>>& grid, vector<vector<bool>>& vis, int x, int y){\n if(x<0 || x>=grid.size() || y<0 || y>=grid[0].size()){\n return 1;\n }\n if(grid[x][y] == 0){\n return... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "\n\nclass Solution {\npublic:\n int vis[1005][1005];\n int ans = 0;\n vector<pair<int, int>> d = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};\n\n int n, m;\n\n bool valid(int ci, int cj) {\n if (ci >= 0 && ci < n && cj >= 0 && cj < m)\n return true;\n else\n return... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n bool vis[101][101];\n int n, m;\n vector<pair<int, int>> d = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};\n bool valid(int ci, int cj) {\n if(ci >= 0 && ci < n && cj >= 0 && cj < m) {\n return true;\n } else {\n return false;\n }\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int ans = 0;\n bool vstd[105][105];\n\n vector<pair<int,int>> pth = {{1,0},{-1,0},{0,1},{0,-1}};\n \n bool isValid(int l , int k , int n , int m){\n if(l>=0 && l<n && k>=0 && k<m && vstd[l][k] == false) {\n return true;\n }\n return... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n bool vis[105][105];\n int ans;\n int r, c;\n vector<pair<int, int>> v = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};\n bool valid(int ci, int cj){\n if(ci >= 0 && ci < r && cj >= 0 && cj < c){\n return true;\n }\n return false;\n }\n v... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n bool visited[105][105];\n vector<int> d[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n bool isValid(int i, int j, int row, int col) {\n if (i < 0 || i >= row || j < 0 || j >= col) {\n return false;\n } else {\n return true;\n }\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int parameter;\n vector<pair<int,int>> d = {{1,0},{-1,0},{0,1},{0,-1}};\n\n bool valid(int i, int j, int n, int m){\n if(i<0 || i>=n || j<0 || j>=m) return false;\n return true;\n }\n\n void dfs(vector<vector<int>>& grid, vector<vector<bool>> &visite... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "#include <vector>\n#include <queue>\n#include <utility>\n\nusing namespace std;\n\nclass Solution {\npublic:\n // Function to check if the cell is valid (within grid bounds)\n bool isvalid(int new_i, int new_j, int m ,int n){\n return new_i >= 0 && new_i < m && new_j >= 0 && new_j < n;\n }\... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\n vector<vector<int>> grid;\n int n,m;\n int dfs(int i, int j, vector<vector<bool>> &vis) {\n if(i<0 || j<0 || i>=n || j>=m || grid[i][j] == 0)\n return 1;\n\n if(vis[i][j]) return 0;\n\n vis[i][j] = 1;\n\n int perimeter = 0;\n\n perim... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int solve(vector<vector<int>>&grid,vector<vector<bool>>&vis,int sr,int sc)\n {\n int n = grid.size();\n int m = grid[0].size();\n\n queue<pair<int,int>>q;\n q.push({sr,sc});\n vis[sr][sc] = true;\n int peri = 0;\n\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\nprivate:\n vector<int> stepCol = {1, 0, -1, 0};\n vector<int> stepRow = {0, 1, 0, -1};\n bool valid(int row, int col, auto& grid) {\n return (row >=0 && row < grid.size() && col >=0 && col < grid[0].size());\n }\npublic:\n int islandPerimeter(vector<vector<int>>& gri... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\n vector<vector<int>> grid;\n int n,m;\n int dfs(int i, int j, vector<vector<bool>> &vis) {\n if(i<0 || j<0 || i>=n || j>=m || grid[i][j] == 0)\n return 1;\n\n if(vis[i][j]) return 0;\n\n vis[i][j] = 1;\n\n int perimeter = 0;\n\n perim... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int m;\n int n;\n vector<vector<int>> direction{{1,0},{-1,0}, {0,1},{0,-1}};\n int bfs(vector<vector<int>>& grid, int i, int j) {\n int perim =0;\n queue<pair<int,int>>q;\n q.push({i,j});\n grid[i][j] =-1;\n while(!q.empty()){\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> directions{{1,0}, {-1,0}, {0,1}, {0,-1}};\n \n int BFS(vector<vector<int>>& grid, int i, int j, int m, int n, int& peri){\n \n queue<pair<int,int>> que;\n que.push({i,j});\n grid[i][j] = -1;\n \n while(!que.e... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int m;\n int n;\n int perimeter;\n //bfs\n vector<vector<int>> directions {{1,0},{-1,0},{0,1},{0,-1}};\n\n int bfs(vector<vector<int>>& grid, int i, int j){\n //use a queue in bfs to store and process the encountered edges\n queue<pair<int,int>> q... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n bool vis[105][105];\n vector<pair<int,int> >d={{0,1},{0,-1},{-1,0},{1,0}};\n int n,m;\n int prt=0;\n bool valid(int i,int j)\n {\n if(i<0 || i>=n || j<0 || j>=m)\n {\n return false;\n }\n return true;\n }\n void bfs(... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\n int bfs(int i, int j, vector<vector<int>>& grid, vector<vector<int>>& vis){\n queue<pair<int, int>> q;\n q.push({i, j});\n vis[i][j] = 1;\n\n int n = grid.size(), m = grid[0].size(), ans = 0;\n\n int rc[] = {-1, 0, 1, 0};\n int cc[] = {0, 1, 0... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int n, m;\n\n int row[4] = {0, 0, -1, 1};\n int col[4] = {-1, 1, 0, 0};\n\n bool valid(int i, int j) {\n return i >= 0 && j >= 0 && i < n && j < m;\n }\n\n int islandPerimeter(vector<vector<int>>& grid) {\n n = grid.size();\n m = grid[0].si... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n int cnt=0;\n int x[]={-1,0,1,0};\n int y[]={0,1,0,-1};\n queue<pair<int,int>>q;\n int n=grid.size();\n int m=grid[0].size();\n vector<vector<int>>vis(n,vector<int>(m,0));\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int calc(int row,int col,vector<vector<int>>& grid){\n int total=4;\n \n int n = grid.size();\n int m = grid[0].size();\n if(row>=0 && row<n && (col-1) >= 0 && col < m && grid[row][col-1]==1)\n total--;\n if((row-1)>=0 && r... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int dx[4] = {-1, 0, 1, 0};\n int dy[4] = {0, -1, 0, 1};\n int islandPerimeter(vector<vector<int>> & grid) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n int n = grid.size(), m = grid[0].size();\n vector<vector<int>> vis(n, vector<i... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n\n // Find first island tile\n int i = 0, j = 0;\n while(i < m) {\n if(grid[i][j])\n break;\n \n j++;\n ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n\n std::queue <pair<int,int>> bfs_queue;\n vector<vector<bool>> visited(grid.size(),vector<bool>(grid[0].size(), 0));\n \n //Push the first occuring land into the bfs \n\n for (int i = 0; i< ... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n int peri = 0;\n queue<pair<int, int>> q;\n vector<int> x = {0, 1, 0, -1};\n vector<int> y = {1, 0, -1, 0};\n vector<vector<int>... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n queue<pair<int, int>> q;\n int rows = grid.size();\n int cols = grid[0].size();\n \n // Find the first land cell and push it to the queue\n bool found = false;\n for(int i = 0;... |
463 | <p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents land and <code>grid[i][j] = 0</code> represents water.</p>
<p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded... | 3 | {
"code": "class Solution {\npublic:\n bool is_valid(std::vector<std::vector<int>>& grid, int r, int c) {\n if (r >= 0 && r < grid.size() && c >= 0 && c < grid[0].size()) {\n if (grid[r][c] == 1 || grid[r][c]==-1)\n return true;\n }\n return false;\n }\n int bfs... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.