id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 2 | {
"code": "class Solution {\npublic:\n int poss(vector<vector<int>> &dis, int val, vector<vector<int>> &vis){\n queue<pair<int,int>>q;\n int n = dis.size();\n if(dis[0][0] < val)return 0;\n vis[0][0] = val + 1;\n q.push({0,0});\n // vis[0][0] = 1;\n int dx[] = {0, 1... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 2 | {
"code": "class Solution {\npublic:\n bool poss(const vector<vector<int>> &dis, int val, vector<vector<int>> &vis) {\n queue<pair<int, int>> q;\n int n = dis.size();\n if (dis[0][0] < val) return false;\n \n q.push({0, 0});\n vis[0][0] = val + 1;\n int dx[] = {0, 1... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 2 | {
"code": "class Solution {\nprivate:\n vector<int> rowDir = {-1, 1, 0, 0};\n vector<int> colDir = {0, 0, -1, 1};\n \n bool isValid(vector<vector<bool>>& visited, int i, int j, int n) {\n return i >= 0 && j >= 0 && i < n && j < n && !visited[i][j];\n }\n \n bool isSafe(vector<vector<int>>&... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 2 | {
"code": "class Solution {\npublic:\n vector<int>rowDir = {-1, 1, 0, 0};\n vector<int>colDir = {0, 0, -1, 1};\n bool isValid(vector<vector<bool>>&visited, int i, int j)\n {\n if (i < 0 || j < 0 || i == visited.size() || j == visited[0].size() || visited[i][j])\n return false;\n r... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 2 | {
"code": "class Solution {\npublic:\n \n bool safe(int r, int c, int n) {\n return(r>=0 && c>=0 && r<n && c<n);\n }\n \n vector<int> x = {-1, 1, 0, 0};\n vector<int> y = {0, 0, -1, 1};\n \n class Comp {\n public:\n bool operator() (vector<int> &a, vector<int> &b) {\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 2 | {
"code": "class Solution {\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n const int dirs[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n const int M = grid.size();\n const int N = M == 0 ? 0 : grid[0].size();\n vector< vector<int> > safeness(M, vector<int>(N, -1));\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\nprivate:\n typedef pair<int, pair<int, int>> ppi;\n\n int n;\n vector<int> delR = {-1, 0, 1, 0}, delC = {0, 1, 0, -1};\n\n bool isValid(int row, int col){\n return row >= 0 && row < n && col >= 0 && col < n;\n }\n\n void bfs(vector<vector<int>>& grid, vector<vect... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int delrow[4] = {-1,0,+1,0};\n int delcol[4] = {0,+1,0,-1};\n\n bool isValid(int row,int col,vector<vector<int>> &grid){\n int n = grid.size();\n if(row >= 0 && row < n && col >= 0 && col < n){\n return true;\n }\n return false;\n... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n const int dirs[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n const int M = grid.size();\n const int N = M == 0 ? 0 : grid[0].size();\n vector< vector<int> > safeness(M, vector<int>(N, -1));\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\n int rows;\n int cols;\n vector<pair<int, int>> directions = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n bool isValidCell(int x, int y) {\n return (x >= 0 && x < rows && y >= 0 && y < cols);\n }\n\n bool bfsPathExists(vector<vector<int>>& distFromThief,\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n vector<int> dr = {0, 0, 1, -1};\n vector<int> dc = {1, -1, 0, 0};\n\n bool isValidDist(int n, int i, int j) {\n return (i >= 0 && i < n && j >= 0 && j < n);\n }\n\n bool isValidSafe(vector<vector<int>>& visited, int n, int i, int j, int safe, vector<vector<... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n vector<int> dx {0,1,0,-1};\n vector<int> dy {1,0,-1,0};\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int n = grid.size() , m = grid[0].size() ;\n if (grid[0][0] || grid[n-1][m-1]) return 0 ;\n queue<pair<int,int>> q;\n for(int i... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n bool dfs(int i,int j,int leastSafety,vector<vector<int>>& safetyFactor,int n,vector<vector<int>>& vis)\n {\n vis[i][j] = 1;\n if(i== n-1 && j == n-1 && safetyFactor[i][j] >= leastSafety)\n {\n return true;\n }\n if(safetyFactor... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n vector<int> dx {0,1,0,-1};\n vector<int> dy {1,0,-1,0};\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int n = grid.size() , m = grid[0].size() ;\n if (grid[0][0] || grid[n-1][m-1]) return 0 ;\n queue<pair<int,int>> q;\n for(int i... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n/*\n Nice: think in the reverse direction i.e. in order to find the shortest \n distance for each cell to to theives (1) whcih will result in tc (n^2*m^2) , \nthink in the opposite fashion i.e. try to start from 1s and reach every 0s in\nminimum possible path using multi source... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n bool solve(vector<vector<int>>& grid, int mid, vector<vector<int>> &safe) {\n if (safe[0][0] < mid) return false;\n int n = grid.size();\n queue<pair<int, int>> q;\n q.push({0, 0});\n vector<vector<int>> vis(n, vector<int>(n, 0));\n v... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\n int dx[4]={0,1,0,-1};\n int dy[4]={1,0,-1,0};\n\n bool possible(int val ,vector<vector<int>>& grid )\n {\n queue<pair<int,int>> q;\n int n=grid.size();\n if(grid[0][0]>=val)\n q.push({0,0});\n vector<vector<int>> vis(n, vector<int>(n,0));\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n\n if(grid[0][0] == 1 || grid[n-1][m-1] == 1){\n return 0;\n }\n\n vector<vector<int>> dis(n,vector<int>(m,-1));\n pri... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int n = grid.size();\n // Do BFS from all the 1s\n vector<vector<int>> distances(n, vector<int>(n, INT_MAX));\n queue<pair<int, int>> q;\n for(int i = 0; i < n; i++) {\n for... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int is_path(vector<vector<int>> &m_dist, int safeness_factor){\n int m = m_dist.size();\n int n = m_dist[0].size();\n queue<pair<int, int>> q;\n vector<vector<int>> vis(m, vector<int>(n, 0));\n if(m_dist[0][0] >= safeness_factor){\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n queue<vector<int>> q;\n int n = grid.size();\n vector<vector<bool>> seen(n, vector<bool>(n));\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (g... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int n;\n vector<vector<int>> g, td, sf;\n vector<vector<int>> dlst = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n g = grid;\n n = g.size();\n td = vector<vector<int>>(n, vector<int>(n, INT_MAX)); ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\n vector<pair<int, int>> dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n bool isValid(int i, int j, vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n if (i >= 0 && i < n && j >= 0 && j < m)\n return true;\n\n return fa... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n \n int dx[4] = {-1, 1, 0, 0};\n int dy[4] = {0, 0, -1, 1};\n \n bool isValid(int x, int y, int n) {\n return (0 <= x && x < n && 0 <= y && y < n);\n }\n \n vector<vector<int>> calculateSafeness(vector<vector<int>>& grid) {\n int n = grid.siz... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int n;\n vector<pair<int, int>> index = {{1,0}, {-1,0}, {0,1}, {0,-1}};\n vector<vector<int>> vis;\n void fillDist(vector<vector<int>>& grid) {\n int k=0; n=grid.size();\n vis.resize(n,vector<int>(n,0));\n queue<pair<int,int>> q;\n for(int... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\nprivate:\n vector<vector<int>> DIRs = {\n {1,0},{0,1},{-1,0},{0,-1}\n };\n\n int dist(int x1, int y1, int x2, int y2) {\n return abs(x1 - x2) + abs(y1 - y2);\n }\n\n struct comp{\n bool operator()(const vector<int>& v1, const vector<int>& v2) {\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int dir[5]={-1,0,1,0,-1};\n queue<vector<int>> q;\n void bfs(vector<vector<int>>& grid,vector<vector<int>>& mDist,int n){\n while(!q.empty()){\n auto vec=q.front();\n int i=vec[0],j=vec[1];\n q.pop();\n for(int d=0;d<4;... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic: \n int dx[4] = {-1, 0, 1, 0};\n int dy[4] = {0, -1, 0, 1};\n int n;\nprivate:\n bool check(vector<vector<int>> &distToNearestThief, int sf)\n {\n queue<pair<int,int>> q;\n \n vector<vector<int>> vis(n, vector<int> (n, 0));\n \... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "//T.C : O(log(n) * n^2)\n//S.C : O(n^2)\n\nclass Solution {\npublic: \n int dx[4] = {-1, 0, 1, 0};\n int dy[4] = {0, -1, 0, 1};\n int n;\nprivate:\n bool check(vector<vector<int>> &distToNearestThief, int sf)\n {\n queue<pair<int,int>> q;\n \n vector<vector<i... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\n bool f(vector<vector<int>> dist, int dis){\n int n=dist.size();\n if(dist[0][0]<dis) return false; \n\n vector<vector<int>> vis(n,vector<int>(n,0));\n\n queue<pair<int,int>> q;\n q.push({0,0});\n vis[0][0]=1;\n\n int dr[4]={-1,0,1,0}, d... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int m, n;\n int dx[4] = {-1, 0, 0, 1};\n int dy[4] = {0, 1, -1, 0};\n \n bool valid(int i, int j) {\n return (i>=0 && j>=0 && i<n && j<n);\n }\n\n bool ok(vector<vector<int>> dist, int d) {\n queue<pair<int, int>> q;\n vector<vector<bool... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n// optimised BFS + Binary search \nint delRow[4]={-1,0,1,0};\nint delCol[4]={0,1,0,-1};\nbool check(int safeDistance,vector<vector<int>>&dp,int n,int m){\n queue<pair<int,int>>q;\n vector<vector<int>>vis(n,vector<int>(m,0));\n q.push({0,0});\n vis[0][0]=1;\n\n if(d... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\nbool possible(int mid,vector<vector<int>>&dis){\n queue<pair<int,pair<int,int>>>q;\n if(dis[0][0]<mid)\n return false;\n q.push({dis[0][0],{0,0}});\n int n=dis.size();\n vector<vector<int>>vis(n,vector<int>(n));\n int dr[]={-1,1,0,0};\n int dc[]={0,0,-1,1}... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n\n if(grid[m - 1][n - 1] == 1){\n return 0;\n }\n queue<vector<int>> q;\n for(int i = 0; i < m; i++){\n for... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n\n if(grid[m - 1][n - 1] == 1){\n return 0;\n }\n queue<vector<int>> q;\n for(int i = 0; i < m; i++){\n for... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n \n \n queue<vector<int>> q;\n int n = grid.size();\n\n if(grid[n-1][n-1] == 1)\n return 0;\n vector<vector<int>> dist(n, vector<int>(n,-1));\n\n for(int i=0; i< n;... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n bool isP(int r, int c, int &safe, vector<vector<int>> &grid, vector<vector<bool>> &isVis){\n if(grid[r][c] < safe) return false;\n \n int n = grid.size();\n\n isVis[r][c] = true;\n\n if(r == (n-1) and c == (n-1)) return true;\n\n vect... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic: \n vector<pair<int, int>> arr = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n bool dfs(int n, int i, int j, int mid, vector<vector<int>>& dist, vector<vector<int>>& visited) {\n if (dist[i][j] < mid) {\n return false;\n }\n if (i == n - 1 && j == n - ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<vector<int>> dist(n, vector<int>(n, 1e5));\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... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n typedef pair<int,pair<int,int>> pii;\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<vector<int>>man(n,vector<int>(n,INT_MAX));\n queue<vector<int>>q;\n vector<int>dirx = {1,-1,0,0}, diry = {0,0,1,-1};\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int dx[4] = {1, 0, -1, 0};\n int dy[4] = {0, 1, 0, -1};\n\n vector<vector<int>> calculateSafenessFactors(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<vector<int>> safeness(\n n, vector<int>(n, INT_MAX)); \n queue<pair<int,... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n void calculateAllOverSafetyOfCells(vector<vector<int>>& grid, \n vector<vector<int>>& safety, int n, int xAxis[], int yAxis[]) \n {\n queue<vector<int>>q ; // steps, row, col\n for(int i=0 ; i<n ; i++)\n {\n for(int j=0 ; j<n ; j++) \n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": " int delrow[] = {0,1,0,-1};\n int delcol[] = {1,0,-1,0};\n\nclass Solution {\npublic:\n vector<vector<int>> bfs(vector<vector<int>>& grid){\n int n=grid.size();\n int m=grid[0].size();\n vector<vector<int>> dist(n,vector<int>(m,0));\n vector<vector<int>> vis(n,vector<int>(m,0... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "using ppi = pair<pair<int, int>, int>;\nclass Solution {\npublic:\n\n bool isOk(vector<vector<int>>& grid, vector<vector<int>>&vis) {\n if (vis[0][0] == 1) return false;\n int n = grid.size();\n int v[] = { -1, 0, 1, 0, -1};\n queue<pair<int, int>> q;\n q.push({0, 0});... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "int sf[401][401];\nint dp[401][401];\n\nclass Solution {\npublic:\n void safecompute(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 ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int dx[4] = {1,-1,0,0};\n int dy[4] = {0,0,-1,1};\n bool bfs(vector<vector<int>>&grid,vector<vector<int>>&dist,int x){\n int n = grid.size();\n vector<vector<int>>vis(n,vector<int>(n));\n vis[0][0] = 1;\n queue<pair<int,int>>q;\n q.pus... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int n,m;\n vector<vector<int>>dist;\n vector<vector<int>>dir{ {-1,0} , {0,1} , {1,0} , {0,-1}};\n \n void preComputeMinDist_bfs(vector<vector<int>>&grid){\n \n queue<vector<int>>q;\n vector<vector<bool>>vis(n,vector<bool>(m,false));\n \n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n bool canReachEnd(vector<vector<int>>& safe, int minSafety) {\n int n = safe.size();\n vector<vector<int>> vis(n, vector<int>(n, 0));\n queue<pair<int, int>> q;\n \n if (safe[0][0] < minSafety) return false;\n \n q.push({0, 0});... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "\nclass Solution {\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n\n int n = int(grid.size());\n\n vector<vector<int>> dists(n, vector<int>(n, -1));\n\n queue<pair<int, int>> q;\n\n int oneCount = 0;\n for (int i = 0; i < n; ++i)\n {\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "\nclass Solution {\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n\n int n = int(grid.size());\n\n vector<vector<int>> dists(n, vector<int>(n, -1));\n\n queue<pair<int, int>> q;\n\n int oneCount = 0;\n for (int i = 0; i < n; ++i)\n {\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "\nclass Solution {\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n\n int n = int(grid.size());\n\n vector<vector<int>> dists(n, vector<int>(n, -1));\n\n queue<pair<int, int>> q;\n\n int oneCount = 0;\n for (int i = 0; i < n; ++i)\n {\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "\nclass Solution {\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n\n int n = int(grid.size());\n\n vector<vector<int>> dists(n, vector<int>(n, -1));\n\n queue<pair<int, int>> q;\n\n int oneCount = 0;\n for (int i = 0; i < n; ++i)\n {\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n bool Check(int i, int j, int n){\n return i < n && j < n && i >= 0 && j >= 0;\n }\n\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n std::queue<std::vector<int>> q;\n int n = grid.size();\n vector<vector<int>> safety(n, vector<int>(... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int solve(vector<vector<int>> &grid)\n {\n int n = grid.size();\n int m = grid[0].size();\n\n vector<vector<int>> safeness(n, vector<int>(m, INT_MIN));\n safeness[0][0] = grid[0][0];\n\n priority_queue<vector<int>> pq;\n pq.push({g... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n bool valid(int row,int col,int n,int m){\n if(row<0 ||row>=n || col<0 || col>=m){\n return false;\n }\n return true;\n }\n bool check(int mid,int n,int m,vector<vector<int>>&dis){\n if(dis[0][0]<mid)return false;\n queue<pai... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n void relax(int& r,int& c,vector<vector<int>>& safeD,vector<vector<int>>& grid,queue<pair<int,int>>& q)\n {\n int i,j,n=grid.size();\n q.push({r,c});\n q.push({-1,-1});\n\n int dist=0;\n while(!q.empty())\n {\n i=q.front(... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int n;\n vector<vector<int>> dir = {{-1,0}, {1,0}, {0,-1}, {0,1}};\n void dfs(vector<vector<int>>& grid, vector<vector<int>>& score) {\n queue<pair<int, int>> q;\n\n for(int i=0; i<n; i++) {\n for(int j=0; j<n; j++) {\n if(grid[i]... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n if(grid[0][0] == 1 || grid[m-1][n-1] == 1){\n return 0 ;\n }\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n if(grid[0][0] == 1 || grid[m-1][n-1] == 1){\n return 0 ;\n }\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class DSU {\npublic:\n DSU(int n) {\n prnt = vector<int>(n + 1);\n val = vector<int>(n + 1);\n for (int i = 1; i <= n; i++) {\n prnt[i] = i;\n val[i] = 1;\n }\n }\n int root(int x) {\n if (x != prnt[x]) {\n return prnt[x] = root(p... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class DisjointSet{\nprivate:\n vector<int> par;\n vector<int> size;\npublic:\n DisjointSet(int n){\n size.resize(n+1,1);\n for(int i=0;i<=n;i++){\n par.push_back(i);\n }\n }\n\n int findUpar(int a){\n if(par[a]==a) return a;\n ... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\n vector<int>dir={0,1,0,-1,0};\n bool isValid(int row,int col,int n){\n return row>=0 && col>=0 && row<n && col<n;\n }\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int n = (int)grid.size();\n if(n==0)return -1;\n vector<vector<... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\n vector<int>dir={0,1,0,-1,0};\n bool isValid(int row,int col,int n){\n return row>=0 && col>=0 && row<n && col<n;\n }\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int n = (int)grid.size();\n if(n==0)return -1;\n vector<vector<... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\n vector<int>dir={0,1,0,-1,0};\n bool isValid(int row,int col,int n){\n return row>=0 && col>=0 && row<n && col<n;\n }\npublic:\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int n = (int)grid.size();\n if(n==0)return -1;\n vector<vector<... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int INF = 1e5;\n vector<int> dr = {-1, 1, 0, 0};\n vector<int> dc = {0, 0, 1, -1};\n\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<vector<int>> costs(n, vector<int>(n, INF));\n vector<vector<int>> dists(... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n\n void dfs(int i,int j,vector<vector<int>> &dis, vector<vector<int>> &vis,int mid)\n {\n if(dis[i][j]<mid) return;\n int n=dis.size();\n vis[i][j]=1;\n int dx[4]={0,0,1,-1};\n int dy[4]={1,-1,0,0};\n for(int k=0;k<4;k++)\n {... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n int INF = 1e5;\n vector<int> dr = {-1, 1, 0, 0};\n vector<int> dc = {0, 0, 1, -1};\n\n int maximumSafenessFactor(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<vector<int>> costs(n, vector<int>(n, INF));\n vector<vector<int>> dists(... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n void bfs(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n \n queue<vector<int>> q;\n \n vector<vector<int>> vis(m, vector<int>(n, 0));\n \n for(int i=0; i<m; i++) {\n for(int j=0... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\nprivate:\n void findDistance(vector<vector<int>>& grid, vector<vector<int>>& dis) {\n int n = grid.size(), m = grid[0].size();\n vector<vector<int>> vis(n + 1, vector<int>(m + 1, 0));\n queue<pair<int, int>> q;\n for(int i = 0; i < n; ++i) {\n for... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\nprivate:\n void findDistance(vector<vector<int>>& grid, vector<vector<int>>& dis) {\n int n = grid.size(), m = grid[0].size();\n vector<vector<int>> vis(n + 1, vector<int>(m + 1, 0));\n queue<pair<int, int>> q;\n for(int i = 0; i < n; ++i) {\n for... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n inline bool isValid(int i, int j, int m, int n) {\n return i >= 0 && i < m && j >= 0 && j < n;\n }\n void updateSafeFactor(int i, int j, vector<vector<int>>& grid, vector<vector<int>> &safeFactor) {\n int m = grid.size();\n int n = grid[0].size();\n... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n inline bool isValid(int i, int j, int m, int n) {\n return i >= 0 && i < m && j >= 0 && j < n;\n }\n void updateSafeFactor(int i, int j, vector<vector<int>>& grid, vector<vector<int>> &safeFactor) {\n int m = grid.size();\n int n = grid[0].size();\n... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n\n typedef pair<int,int> pii;\n typedef vector<vector<int>> vvi;\n typedef vector<int> vi;\n\n vi rows = {-1, 0, 1, 0};\n vi cols = {0, 1, 0, -1};\n\n bool pathPossible(vvi grid, int reqSafeness){\n\n int n = grid.size();\n\n if(grid[0][0] < reqSaf... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "class Solution {\npublic:\n void bfs(vector<vector<int>>&vis, vector<vector<int>>&grid, int val){\n queue<pair<int,int>> q;\n int n = grid.size();\n int m = grid[0].size();\n\n if(grid[0][0] < val){\n return;\n }\n q.push({0,0});\n int... |
2,914 | <p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>n x n</code>, where <code>(r, c)</code> represents:</p>
<ul>
<li>A cell containing a thief if <code>grid[r][c] = 1</code></li>
<li>An empty cell if <code>grid[r][c] = 0</code></li>
</ul>
<p>You are initially positioned at cell <... | 3 | {
"code": "typedef vector<int> vi;\ntypedef vector<vi> vvi;\ntypedef vector<pair<int,int>> vp;\ntypedef pair<int, int> cell;\nclass Solution {\npublic:\n // conditions:\n // 1. move in adjacent directions\n // 2. safeness factor is minimum manhattan dist to a thief\n // mahattan distance: |a - x| + |b ... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n static const bool Booster ... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n static const bool Booster ... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n\n\nclass Solution {\npubli... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\n ListN... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "static const int fastIO = [] {\n\tstd::ios_base::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);\n\treturn 0;\n}();\n\nclass Solution {\nprivate:\n\tint solve(ListNode* node) {\n\t\tif (!node) return 0;\n\t\tnode->val = node->val * 2 + solve(node->next);\n\t\tint carry = node->val / ... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n int rec(ListNode*& root,in... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n int rec(ListNode*& root,in... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n int rec(ListNode*& root,in... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "class Solution {\npublic:\n void helper(ListNode* h1,ListNode* h2,ListNode* &nh){\n if(h2->next == NULL){\n nh = h2;\n h2->next = h1;\n return;\n }\n helper(h1->next,h2->next,nh);\n h2->next = h1;\n }\n ListNode* reverseList(ListNode* h... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "class Solution {\npublic:\n void helper(ListNode* h1,ListNode* h2,ListNode* &nh){\n if(h2->next == NULL){\n nh = h2;\n h2->next = h1;\n return;\n }\n helper(h1->next,h2->next,nh);\n h2->next = h1;\n }\n ListNode* reverseList(ListNode* h... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,871 | <p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.