id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n set<pair<int,int>> land;\n int m = grid.size();\n int n = grid[0].size();\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n if(grid[i][j]==1) land.insert({i,j});\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int R = grid.size(), C = grid[0].size();\n queue<pair<int, int>> q;\n vector<vector<bool>> seen(R, vector<bool>(C, false));\n vector<vector<int>> distances(R, vector<int>(C, INT_MAX));\n int ans... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\nint bfs(vector<pair<int, int>> before, vector<vector<bool>>& visited, vector<vector<int>>& grid) {\n queue<pair<pair<int, int>, int>> q;\n for (int i = 0; i < before.size(); i++) {\n q.push({{before[i].first, before[i].second}, 0});\n visited[before[i].first][... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n\n bool validPoint(int p, int q, int n, int m){\n if(p<0 || p>=n || q<0 || q>=m) return false;\n return true;\n }\n\n int maxDistance(vector<vector<int>>& grid) {\n \n int n = grid.size(), m = grid[0].size();\n queue<pair<pair<int,int>,... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n\n bool validPoint(int p, int q, int n, int m){\n if(p<0 || p>=n || q<0 || q>=m) return false;\n return true;\n }\n\n int maxDistance(vector<vector<int>>& grid) {\n \n int n = grid.size(), m = grid[0].size();\n queue<pair<pair<int,int>,... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n\n vector<vector<int>> dis;\n vector<vector<int>> vis;\n\n void bfs(queue<pair<int,int>> q,vector<vector<int>>& grid)\n {\n int n=grid.size();\n while(!q.empty())\n {\n auto node=q.front();\n q.pop();\n if(vis[node... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n void bfs(int i,int j,vector<vector<int>>& grid){\n \n }\n \n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n queue<pair<int,int>> q,q1;\n int row[] = {1,0,-1,0};\n int col[] = {0,1,0,-1};\n\n for(int i=0... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n queue<pair<int,int>>q;\n int steps=0, r=grid.size(), c=grid[0].size();\n for(int i=0; i<r; i++) {\n for(int j=0; j<c; j++) {\n if(grid[i][j]==1) {\n q.push({i-1,j}... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n = size(grid), m = size(grid[0]), res = 0;\n\n queue<pair<int, int>> q, q1;\n\n for(int i = 0; i < n; i++)\n for(int j = 0; j < m; j++)\n if(grid[i][j] == 1){\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "\n\n\nclass Solution {\n void solve(int ni, int nj, map<pair<int, int>, int>& q, vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n int dis = INT_MAX;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if (... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n queue<pair<int,int>> q;\n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n if(grid[i][j]==1){\n q.push({i,j});\n }\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n\n bool isvalid(int x, int y, vector<vector<int>>& grid, set<pair<int,int>> &visited){\n int n = grid.size(); int m = grid[0].size();\n if(x>=0 && x<n && y>=0 && y<m && grid[x][y]==0 && visited.find({x,y})==visited.end()){\n return true;\n }\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n vector<int>g[105];\n int dist[1001][1001];\n int vis[1001][1001];\n int n,m;\n bool f=true,ff=true;;\n\nbool isValid(int x, int y) {\n if(x<0 || x>=n || y<0 || y>=m) return false;\n if(vis[x][y]==1) return false;\n return true;\n}\n\nint dx[4]={-1,0,1,0};... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n vector<int>g[105];\n int dist[1001][1001];\n int vis[1001][1001];\n int n,m;\n bool f=true,ff=true;;\n\nbool isValid(int x, int y) {\n if(x<0 || x>=n || y<0 || y>=m) return false;\n if(vis[x][y]==1) return false;\n return true;\n}\n\nint dx[4]={-1,0,1,0};... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n vector<int>g[105];\n int dist[1001][1001];\n int vis[1001][1001];\n int n,m;\n bool f=true,ff=true;;\n\nbool isValid(int x, int y) {\n if(x<0 || x>=n || y<0 || y>=m) return false;\n if(vis[x][y]==1) return false;\n return true;\n}\n\nint dx[4]={-1,0,1,0};... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "#define ll long long\nclass Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n vector<pair<ll,ll> > cur;\n ll n = grid.size();\n ll m = grid[0].size();\n ll max = 1000000007;\n vector<vector<ll> > dis(n,vector<ll>(m,max));\n for(ll i=0; i<n;i++... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n using state=pair<int,int>;\n int N,M;\n vector<vector<int>>vis;\n vector<vector<int>>dis;\n bool isvalid(int x,int y){\n if(0<=x && x<N && 0<=y && y<M && vis[x][y]==0){\n return 1;\n }\n return 0;\n }\n vector<state>neigh(stat... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "#include <assert.h>\n\nclass Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n const int n = grid.size();\n vector< pair<int, int> > cur;\n cur.reserve(n*n);\n\n for(int i = 0; i < n; ++i) {\n for(int j = 0; j < n; ++j) {\n if(grid... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int res = 0;\n queue<pair<int,int>> q;\n \n //find all lands and add them to q (as start points of the bfs) (first step)\n for (int i = 0; i < grid.size(); i++)\n for (int j = 0; j <... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n\n int maxDistance(vector<vector<int>>& grid){\n\n int n=grid.size(),m=grid[0].size();\n \n queue<pair<int,int>>q;\n\n for(int i = 0; i < n; i++)\n {\n for(int j=0; j < m; j++)\n {\n if(grid[i][j] == 1) q.p... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid)\n {\n int dirs[4][2] = { { -1, 0 }, { 0, 1 },\n { 1, 0 }, { 0, -1 } };\n queue<pair<int, int>> *q;\n int i, i1, j, j1, k, n, *p, r, u, v, * *w;\n bool * *g;\n\n n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid)\n {\n int dirs[4][2] = { { -1, 0 }, { 0, 1 },\n { 1, 0 }, { 0, -1 } };\n queue<pair<int, int>> *q;\n int cMax, i, i1, j, j1, k, n, r, u, v, * *w;\n bool * *g;\n\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int dx[4] = {1,-1,0,0};\n int dy[4] = {0,0,1,-1};\n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n int vis[n+1][n+1];\n memset(vis , -1, sizeof vis);\n\n queue<array<int,3>>q;\n int maxDis = -1;\n\n for(in... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int dx[4] = {1,-1,0,0};\n int dy[4] = {0,0,1,-1};\n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n int vis[n+1][n+1];\n memset(vis , -1, sizeof vis);\n\n queue<array<int,3>>q;\n int maxDis = -1;\n\n for(in... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "#define ppi pair<int,int>\nclass Solution {\npublic:\n int n;\n queue<ppi> q;\n vector<ppi> dir={{0,1} ,{0,-1} ,{1,0} ,{-1,0}};\n unordered_set<string> visited;\n string trr(int i,int j)\n {\n return to_string(i)+\".\"+to_string(j);\n }\n int bfs(vector<vector<int>>& grid)\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution\n{\npublic:\n int maxDistance(vector<vector<int>> &grid)\n {\n int i, j, m = grid.size(), n = grid[0].size();\n queue<vector<int>> q;\n for (i = 0; i < m; i++)\n {\n for (j = 0; j < n; j++)\n {\n if (grid[i][j])\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n queue<pair<int, pair<int, int>>> fifo;\n vector<vector<bool>> visited(grid.size(), vector<bool>(grid[0].size(), false));\n \n for(int i = 0; i < grid.size(); i++){\n for(int j = 0; j < grid[... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\nprivate:\n vector<int> dr = {1, 0, -1, 0};\n vector<int> dc = {0, -1, 0, 1};\n\npublic:\n bool isValid(int row, int col, int n) {\n return (row >= 0 && row < n && col >= 0 && col < n);\n }\n\n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<vector<int>> vis(n,vector<int>(n,0));\n\n queue<pair<pair<int,int>,int>> q;\n\n for(int i = 0; i < n; i++){\n for(int j = 0; j < n; j++){\n if(gr... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<vector<int>> vis(n,vector<int>(n,-1));\n queue<vector<int>> q;\n for(int i = 0; i < n; i++){\n for(int j = 0; j < n; j++){\n if(grid[i][j]==1){\n... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n=grid.size(),ans=-1;\n queue<vector<int>>q;\n vector<vector<int>>vis(n, vector<int>(n,0));\n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n if(grid[i][j]){\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n bool check(int i,int j,int n) {\n if(i<0 or j<0 or i==n or j==n) return false;\n return true;\n }\n\n int maxDistance(vector<vector<int>>& grid) {\n int res = 0;\n queue<vector<int>> q;\n int n = grid.size();\n vector<vector<int... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n // if grid is empty we should return -1\n if (grid.size() == 0) { return -1; }\n\n std::vector<std::pair<int, int>> direcs;\n direcs.push_back({-1, 0});\n direcs.push_back({1, 0});\n dire... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n\n set<pair<int,int>> st;\n queue<pair<int,int>> q;\n\n for(int i = 0 ;i<n ; i++)\n {\n for(int j = 0 ;j <n ; j++)\n {\n if(grid[i][j]=... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int maxDist = -1;\n vector<pair<int,int>> dirs={{0,1},{0,-1},{1,0},{-1,0}};\n set<pair<int,int>> visited;\n queue<pair<int,int>> q;\n for(int x=0;x<grid.size();x++){\n for(int y=0;y<g... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n vector<pair<int,int>> dirs = {{0,1},{0,-1},{1,0},{-1,0}};\n queue<pair<int,int>> q;\n map<pair<int,int>,int> mp;\n for(int x=0;x<grid.size();x++){\n for(int y=0;y<grid[0].size();y++){\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n queue<pair<int,int>> q;\n map<pair<int,int>,int> mp;\n vector<pair<int,int>> dirs={{0,1},{0,-1},{1,0},{-1,0}};\n for(int x=0;x<grid.size();x++){\n for(int y=0;y<grid[0].size();y++){\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n int ans = -1;\n queue<pair<pair<int, int>, int>> q;\n set<pair<int,int>>vis;\n for (int i = 0; i < n; i+... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n queue<pair<int,int>> q;\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n if(grid[i][j] == 1){\n q.push({i,j})... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& arr) {\n int sum = 0;\n int n = arr.size();\n for (int i = 0; i< n; i++){\n for (int j = 0; j< n; j++){\n sum += arr[i][j];\n }\n }\n if (sum == 0 || sum == n*n){\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& arr) {\n int sum = 0;\n int n = arr.size();\n for (int i = 0; i< n; i++){\n for (int j = 0; j< n; j++){\n sum += arr[i][j];\n }\n }\n if (sum == 0 || sum == n*n){\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n int ans=0,count=0;\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n count+=grid[i][j];\n }\n }\n if(coun... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n=grid.size();\n vector<vector<int>> dis(n,vector<int>(n,INT_MIN));\n int ans=-1;\n queue<pair<int,pair<int,int>>> q;\n\n for(int i=0;i<n;i++)\n {\n for(int j=0;j<n;j++)\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n=grid.size();\n int m = grid[0].size();\n\n vector<vector<int>> ans(n,vector<int>(m,0));\n queue<pair<int,pair<int,int>>> q;\n\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n\n queue<pair<pair<int, int>, int> > q;\n int n=grid.size();\n int m=grid[0].size();\n\n vector<vector<int> > vis(n, vector<int>(m, 0));\n\n vector<vector<int> > dis(n, vector<int>(m, -1));\n\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<vector<int>> ones,zers;\n for(int i = 0; i < n; i++){\n for(int j = 0; j < n; j++){\n if(grid[i][j]==1) ones.push_back({i,j});\n else zer... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n \n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<vector<int>> one,zero;\n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n if(grid[i][j]==1) one.push_back({i,j});\n else zero.push_b... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n list<vector<int>> nexts;\n\n int ans = -1;\n\n for (int i = 0; i < grid.size(); i++) {\n for (int j = 0; j < grid.size(); j++) {\n if (grid[i][j] == 1) {\n nexts.p... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n bool isValid(int x, int y, int n){\n return (x>=0 && y>=0 && x<n && y<n);\n }\n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n queue<vector<int>> q;\n int ans = -1e9;\n for(int i=0; i<n; i++){\n for(in... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n // Looks like a BFS problem where we need to find max level\n int maxDistance(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n queue<vector<int>> q;\n for(int i=0; i<m; i++) {\n for(int j=0; j<n; j++) {\... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n queue<vector<int>>q;\n int n = grid.size();\n int m = grid[0].size();\n\n for(int i=0;i<n;i++){\n for(int j =0;j<m;j++){\n if(grid[i][j]==1) q.push({i,j,0});\n }\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n=grid.size();\n int dx[]={-1, 0, 1, 0};\n int dy[]={0, -1, 0, 1};\n vector<vector<bool>> visited(n, vector<bool>(n, false));\n queue<vector<int>> q;\n\n for (int i = 0; i < n; i++) {... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\nvector<vector<int>> dirs = {{0,1},{1,0},{0,-1},{-1,0}};\n int maxDistance(vector<vector<int>>& grid) {\n int m=grid.size(),n = grid[0].size();\n vector<vector<bool>> visited(m,vector<bool>(n,false));\n int res = -1;\n queue<vector<int>> q;\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n \n vector<int>dx = {0, 0, 1, -1};\n vector<int>dy = {1, -1, 0, 0};\n \n int n=grid.size(), m=grid[0].size();\n \n vector<vector<int>>dis(n, vector<int>(m, -1));\n\n queue<ve... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\nint dx[4]={-1,0,1,0};\nint dy[4]={0,1,0,-1};\nint valid(int x,int y,int n,int m){\n if(x<0||x>=n||y<0||y>=m)return 0;\n return 1;\n}\n int maxDistance(vector<vector<int>>& v) {\n int n=v.size(),m=v[0].size();\n queue<vector<int>>q;\n vector<vector<in... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\n vector<int> dr = {0, 0, 1, -1};\n vector<int> dc = {1, -1, 0, 0};\n\npublic:\n bool isPos(int r, int c, int n) {\n return (r >= 0 && c >= 0 && r < n && c < n);\n }\n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<vector<in... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n vector<int> dx = {-1,1,0,0};\n vector<int> dy = {0,0,-1,1};\n int n = grid.size();\n vector<vector<int>> visited(n,vector<int>(n,false));\n vector<vector<int>> distance(n,vector<int>(n,INT_MAX))... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n vector<int> dx = {-1,1,0,0};\n vector<int> dy = {0,0,-1,1};\n int n = grid.size();\n vector<vector<int>> visited(n,vector<int>(n,false));\n vector<vector<int>> distance(n,vector<int>(n,INT_MAX))... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int ans = INT_MIN;\n queue<vector<int>> q;\n int n = grid.size();\n\n for(int i = 0 ; i<n ; i++)\n {\n for(int j = 0 ; j<n ; j++)\n {\n if(grid[i][j]==1)\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int rows = grid.size(), cols = grid[0].size();\n deque<tuple<int,int>> q;\n set<tuple<int,int>> seen;\n\n for (int r=0; r<rows; ++r)\n for (int c=0; c<cols; ++c) {\n if (grid[... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n \n queue<vector<int>> q;\n\n for(int i=0;i<grid.size();i++)\n {\n for(int j=0;j<grid[0].size();j++)\n {\n if(grid[i][j] == 1)\n q.push({i,j,0});\... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n\n int bfs(vector<vector<int>>& grid, queue<vector<int>>& q){\n\n int maxD=-1;\n vector<vector<int>> visited(grid.size(), vector<int>(grid[0].size(), false));\n while(!q.empty()){\n int x=q.front()[0];\n int y=q.front()[1];\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "#define pi pair<int,int>\n#define mk make_pair\nclass Solution {\npublic:\n\n bool valid(int i,int j,int n){\n if (i<0 or j<0 or i>=n or j>=n) return false;\n return true;\n }\n int maxDistance(vector<vector<int>>& grid) {\n int n = grid.size();\n queue<pi> q;\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> visited;\n vector<vector<int>> dist;\n vector<int> dx;\n vector<int> dy;\n bool check(int x,int y,vector<vector<int>>& grid){\n if(x<0 || x>=grid.size() || y<0 || y>=grid.size()) return false;\n return true;\n }\n vector<pai... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> visited;\n vector<vector<int>> dist;\n vector<int> dx;\n vector<int> dy;\n bool check(int x,int y,vector<vector<int>>& grid){\n if(x<0 || x>=grid.size() || y<0 || y>=grid.size()) return false;\n return true;\n }\n vector<pai... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int BFS(vector<vector<int>>& grid)\n {\n // u,v,dist\n queue<vector<int>>q;\n int m=grid.size(),n=grid[0].size();\n vector<vector<bool>>vis(m,vector<bool>(n,false));\n for(int i=0;i<m;i++)\n {\n for(int j=0;j<n;j++)\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int m=grid.size();\n int n=grid[0].size();\n auto cheak=[&](int x,int y) {\n return x>=0 && x<m && y>=0 && y<n;\n };\n vector<vector<int>>direction{{0,1},{0,-1},{1,0},{-1,0}};\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n=grid.size();\n queue<pair<int,int>>q;\n for(int i=0;i<grid.size();i++)\n {\n for(int j=0;j<grid[0].size();j++)\n {\n if(grid[i][j]==1)\n {\n ... |
1,117 | <p>Given an <code>n x n</code> <code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or ... | 3 | {
"code": "class Solution {\npublic:\n int maxDistance(vector<vector<int>>& grid) {\n int n=grid.size();\n deque<pair<int,int>> q;\n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n if(grid[i][j]==1){\n q.push_back({i,j});\n }\n ... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 0 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int c=0;\n for(int i=0;i<words.size();i++){\n int t=1;\n for(int j=0;j<words[i].size();j++){\n int f=0;\n for(int k=0;k<allowed.size();k++){... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 0 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int bitmask=0;\n for(auto i:allowed){\n \n bitmask=bitmask|1<<(i-'a');\n }\nint ans=0;\n for(auto i:words){\n bool flag=0;\n for(auto ... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 0 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int count = 0;\n for(string s: words){\n bool isallowed = true;\n for(char c: s){\n if(allowed.find(c) == string::npos){\n isallowed = f... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 0 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int count=0;\n bool c=true;\n for(int i=0;i<words.size();i++){\n string s1=words[i];\n for(int j=0;j<s1.length();j++){\n c=allowed.contains(s1[j]);\... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n unordered_set<char> allowed_chars;\n\n int result{};\n\n for (char ch : allowed) {\n allowed_chars.insert(ch);\n }\n\n for (string str : words) {\n\n ... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n unordered_set<char> allowed_chars;\n\n int result{};\n\n for (char ch : allowed) {\n allowed_chars.insert(ch);\n }\n\n for (string str : words) {\n\n ... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n map<char, int> allow;\n for (auto i : allowed) {\n allow[i]++;\n }\n\n int count = 0;\n for (auto x : words) {\n bool flag = true;\n for (... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n unordered_map<char, int> map;\n for(char ch: allowed)\n map[ch]++;\n\n int ans=0;\n for(string word: words){\n bool temp=true;\n for(char ch: wor... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string &allowed, vector<string>& words) {\n int ans;\n for (int i = 0; i < 500; ++i) {\n ans = countConsistentStrings1(allowed, words);\n }\n return ans;\n }\n\n int countConsistentStrings1(string allowed... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int hash[1000] = {0};\n for(int i = 0 ;i < allowed.size() ; i++){\n hash[allowed[i]]++;\n }\n int count = 0;\n for(auto it : words){\n for(int i = 0 ... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int n = allowed.length();\n set<char> vishu;\n vector<int>pappu;\n map<string,bool>anu;\n int counter = 0;\n for (auto i : allowed) {\n vishu.insert(i);\... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int n=allowed.size();\n vector<int>anu;\n set<int>vishu;\n for(auto i:allowed){\n vishu.insert(i);\n }\n for(auto i:words){\n for(auto j:i){\n... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n vector<int> al(26, 0);\n for (auto a : allowed) {\n al[a-'a']++;\n }\n int ans = 0;\n vector<int> a(words.size(), 1);\n for (int i = 0; i < words.size();... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(const string& allowed, vector<string>& words) {\n unordered_set<char> set(begin(allowed), end(allowed));\n return count_if(begin(words), end(words), [&set](string& word) {\n return all_of(begin(word), end(word), [&set](char ... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(const std::string& allowed, const std::vector<std::string>& words) {\n std::unordered_set<char> allowed_set(allowed.begin(), allowed.end());\n \n return std::count_if(words.begin(), words.end(), [&](const std::string& word) {\n ... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n unordered_set<char> allow(allowed.begin(), allowed.end());\n int res = 0;\n for(const auto& word: words) {\n if(std::all_of(word.begin(), word.end(), [&](char c){return allow... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n std::unordered_set<char> m(allowed.begin(), allowed.end());\n int count = 0;\n for (const auto& w : words)\n {\n bool consistent = std::all_of(w.begin(), w.end(), [&m]... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(const string& allowed, const vector<string>& words) {\n const std::unordered_set<char> allowed_set(allowed.begin(),allowed.end());\n return std::count_if(words.begin(), words.end(), [&allowed_set](const std::string& word){\n ... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n unordered_set<char> s(allowed.begin(), allowed.end());\n int ans = 0;\n for(auto &word: words) {\n ans+=all_of(word.begin(), word.end(), [&](char c){\n return ... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n std::unordered_set allowed_chars(allowed.begin(), allowed.end());\n auto is_allowed_word = [&allowed_chars](const std::string& word) {\n return std::all_of(\n word.be... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int ans = 0;\n unordered_map<char, bool>mp;\n for(auto &c: allowed) mp[c] = 1;\n for(auto &word : words)\n ans += all_of(begin(word), end(word), [&](char c){ return mp... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\n unordered_set<char> a{};\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n a = unordered_set<char>{begin(allowed), end(allowed)};\n return count_if(begin(words), end(words), [this](string w) {\n return all_of(cbegin(w), cend(w... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int preparebitmask(string s){\n int allow = 0;\n for(auto i : s){\n // turn i - 'a' bit = 1; in allow\n allow |= (1<<(i-'a'));\n }\n return allow;\n }\n int countConsistentStrings(string allowed, vector<string>& words) {... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n unordered_set<char> a{begin(allowed), end(allowed)};\n return count_if(begin(words), end(words), [&a](string w) {\n return all_of(cbegin(w), cend(w), [&a](auto c){\n ... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n unordered_map<char, int> mp;\n for(auto it:allowed) mp[it]++;\n int size=mp.size();\n int cnt=0;\n for(int i=0; i<words.size(); i++){\n bool temp=true;\n ... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(const string& allowed, const vector<string>& words) {\n return count_if(cbegin(words), cend(words), [allowed = unordered_set<char>{cbegin(allowed), cend(allowed)}](const auto& word) {\n return all_of(cbegin(word), cend(word), [&all... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) \n { \n vector<int> bs ; \n int n = words.size() ; \n for(int i =0 ; i < n ; i ++) \n {\n int num = 0 ; \n for(auto c : words[i]) \n {\n ... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) \n {\n unordered_map<char,int>m;\n for(auto i:allowed)\n m[i]++;\n int temp=0;\n int l=m.size(),cnt=0;\n for(auto i:words)\n {\n for(auto x:i)\n ... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int n_consistent=0;\n // set<char> \n for(int i=0;i<words.size();i++)\n {\n if(isConsistent(allowed, words[i]))\n n_consistent++;\n }\n re... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int c = 0;\n for(auto x : words){\n if(consistent(x, allowed)){\n c++;\n }\n }\n return c;\n }\n bool consistent(string s, string allow... |
1,786 | <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
<p>Return<em> the number of <strong>consistent</strong> st... | 3 | {
"code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n map<char,int>mp;\n for(auto i:allowed)mp[i]++;\n int fix = mp.size();\n int count =words.size();\n for(int i=0;i<words.size();i++){\n string temp = words[i];\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.