id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n\n//using dfs stack\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n = grid.size();\n int m = grid[0].size();\n\n health=health-(grid[0][0]==1?1:0);\n if(health<1)return false;\n\n vector<pair<int,int>> dir{{-1,0},{1,0},{0,-1...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size();\n if (m == 0) return false;\n int n = grid[0].size();\n if (n == 0) return false;\n\n // Directions: up, down, left, right\n vector<pair<int, int>> dire...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n vector<vector<bool>> visited;\n int dp[51][51][201]; // Including health as part of the dp state.\n\n bool solve(vector<vector<int>>& grid, int x, int y, int n, int m, int health) {\n // Out of bounds check\n if (x < 0 || y < 0 || x >= n || y >= m || healt...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n \n\n deque<vector<int>> d;\n int m = grid.size();\n int n = grid[0].size();\n vector<vector<int>>dis(m , vector<int>(n,1e9));\n // dis[0][0];\n\n d.push_back({0,0,0})...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n constexpr int dirs[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n const int m = static_cast<int>(grid.size()),\n n = static_cast<int>(grid[0].size());\n const int initial_health ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "#include<bits/stdc++.h>\nusing namespace std;\nclass Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n constexpr int dirs[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n const int m = grid.size();\n const int n = grid[0].size();\n const int initialHealth = ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n\n int m = grid.size();\n int n = grid[0].size();\n bool ans = false;\n vector<vector<int>> direction = {{1,0},{-1,0},{0,1},{0,-1}};\n vector<vector<int>> sptSet(m, vector<int> (n,I...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n int m, n;\n int directions[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; // down, right, up, left\n int dp[51][51][3000];\n // bool findSafeWalk(vector<vector<int>>& grid, int health) {\n // m = grid.size();\n // n = grid[0].size();\n // memset(dp,...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n vector<vector<pair<int,int>>> adj;\n vector<int> vis;\n vector<int> row = {-1,0,1,0};\n vector<int> col = {0,1,0,-1};\n vector<int>safe ;\n\n void bfs(int node, int val, int n, int m){\n int final = (n-1)*50+(m-1);\n //cout<<final<<endl;\n ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n\n typedef vector<int> v;\n\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int row = grid.size();\n int col = grid[0].size();\n\n vector<vector<int>> update = {{1,0}, {0,1}, {-1,0}, {0,-1}};\n\n vector<vector<bool>> vis(row, vecto...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<int>> v(n,vector<int>(m,0));\n queue<pair<pair<int,int>,int>> q;\n q.push({{0,0},health-grid[0][0]});\n v[0][0...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n//doing bfs to track every possible ways \n //joyram\n bool findSafeWalk(vector<vector<int>>& grid, int h) {\n int m = grid.size();\n int n = grid[0].size();\n\n \n queue<pair<pair<int, int>, int>> q;\n \n \n \n vector<vector<int>> v(m, vector...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\nprivate:\n bool ans = false;\n int r, c;\n vector<int> pos = {0, 1, 0, -1, 0};\n\n struct hash_pair {\n template <class T1, class T2>\n std::size_t operator ()(const std::pair<T1, T2>& p) const {\n auto h1 = std::hash<T1>{}(p.first);\n auto ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "#include <vector>\n#include <unordered_map>\n#include <utility>\n#include <functional>\n\nusing namespace std;\n\nclass Solution {\nprivate:\n bool ans = false;\n int r, c;\n vector<int> pos = {0, 1, 0, -1, 0};\n\n // Define the hash function for pairs\n struct hash_pair {\n template ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n#define ll long long\n vector<vector<bool>> vis;\n vector<vector<vector<ll>>> dp;\n\n bool solve(vector<vector<int>>& grid,ll row,ll col,ll h){\n ll n = grid.size();\n ll m =grid[0].size();\n\n if(row<0 ||row>=n || col <0 || col>=m || h<=0 || vis[row...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "\nclass Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n = grid.size();\n int m = grid[0].size();\n set<pair<int, pair<int, int>>> s;\n vector<vector<int>> maxHealth(n, vector<int>(m, -1));\n vector<pair<int, int>> dir = {{1, 0},...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n int n, m;\n int dir[4] = {-1, 0, 1, 0};\n int dic[4] = {0, -1, 0, 1};\n \n bool solveDp(int i, int j, vector<vector<int>> &grid, int health, vector<vector<vector<int>>> &dp){\n if(i==0 && j==0 && ((grid[i][j] == 0 && health > 0) || (grid[i][j] == 1 && healt...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool dfs(int i, int j,int health, vector<vector<int>>& grid,int m,int n, vector<vector<vector<int>>> &dp)\n {\n if(health==0)\n return false;\n\n //base case\n if(i==(n-1) && j==(m-1))\n {\n if((health)>0) \n ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool recursiveSolution(vector<vector<int>> &grid,vector<vector<int>> &isVisited,int i,int j,int health,vector<vector<vector<int>>> &dp){\n if(i==grid.size()-1 && j==grid[0].size()-1) //base case of the recursion\n return true;\n\n if(dp[i][j][health]...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n vector<int>dx={-1,0,1,0};\n vector<int>dy={0,1,0,-1};\n int n,m;\n bool solve(int r,int c,vector<vector<int>>& grid, int health,vector<vector<int>>& vis,vector<vector<vector<int>>>&dp)\n {\n if(health == 0)return dp[r][c][health]=0;\n if(health<=0)re...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\n int level[51][51];\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int r = grid.size();\n int c = grid[0].size();\n memset(level, 0, sizeof(level));\n\n queue<vector<int>> q;\n\n if(grid[0][0] == 1) health--;\n if(he...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\nbool valid(vector<vector<int>>& grid, int i, int j) {\n return i >= 0 && i < grid.size() && j >= 0 && j < grid[0].size();\n}\n\nbool helper(vector<vector<int>>& grid, vector<vector<vector<int>>>& memo, vector<vector<bool>>& visited, int health, int i, int j) {\n if (!valid(...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n vector <int> dx={-1,1,0,0};\n vector <int> dy={0,0,-1,1};\n bool valid (int i,int j,int n,int m) {\n return i>=0 and i<n and j>=0 and j<m;\n }\n bool solve(int i,int j, int health,vector<vector<int>>& grid) {\n int n=grid.size(),m=grid[0].size();\n ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool isValid(int currRow, int currCol, int m, int n) {\n return currRow >= 0 && currRow < m && currCol >= 0 && currCol < n;\n }\n\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size();\n int n = grid[0].size();\n\n ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size(), n = grid[0].size();\n vector<vector<int>> directions = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n \n vector<vector<int>> dist(m, vector<int>(n, -1));\n \n queue<vector<int>> q;\n ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool check(int x, int y, int m, int n){\n return x >= 0 && x < m && y >= 0 && y < n;\n }\n vector<pair<int, int>> ds = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size();\n int n...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n int rows[4] = {0, 0, 1, -1};\n int cols[4] = {1, -1, 0, 0};\n\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size();\n int n = grid[0].size();\n vector<vector<vector<int>>> dp(m, vector<vector<int>>(n, vector<int>(health...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size(), n = grid[0].size();\n \n vector<vector<vector<int>>> dp(m, vector<vector<int>>(n, vector<int>(health + 1, -1)));\n \n queue<tuple<int, int, int>> q;\n q.pus...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n vector<pair<int,int>> mov = {{0,1},{1,0},{0,-1},{-1,0}};\n bool findSafeWalk(vector<vector<int>>& v, int h) {\n int n = v.size();\n int m = v[0].size();\n vector<vector<vector<int>>> vis(n+1,vector<vector<int>>(m+1,vector<int>(h+1)));\n queue<tu...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n \n int n = grid.size();\n int m = grid[0].size();\n \n queue<vector<int>> qe;\n \n if(grid[0][0] == 1)\n health--;\n \n qe.push({0,0,health})...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\nint m,n;\nint dp[51][51][5010];\n\n\nbool solver(vector<vector<int>>& grid, int health,int i,int j,vector<vector<int>>&vis){\nif(i==m-1&&j==n-1){\n return ((health-grid[i][j])>=1);\n}\nif(health<1)\n{\n return false;\n // return dp[i][j][health+2501]=false;\n }\n\nif(...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\nint m,n;\nint dp[51][51][5010];\n\n\nbool solver(vector<vector<int>>& grid, int health,int i,int j,vector<vector<int>>&vis){\nif(i==m-1&&j==n-1){\n return ((health-grid[i][j])>=1);\n}\nif(health<1)\n{\n return false;\n // return dp[i][j][health+2501]=false;\n }\n\nif(...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n int dp[51][51][252]; // 3D DP array to store state: (i, j, remaining health)\n\n bool findSafeWalk(vector<vector<int>>& v, int health) {\n int n = v.size(); // number of rows\n int m = v[0].size(); // number of columns\n \n memset(dp, -1, sizeof...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n typedef pair<int, int> pii;\n typedef pair<pair<int, int>, int> ppi;\n typedef pair<int, pair<int, int>> pip;\n int dir[5] = {1, 0, -1, 0, 1};\n int helper(map<pii, vector<ppi>> al, int m, int n, int start_d){\n priority_queue<pip, vector<pip>, greater<pip>...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n int n, m;\n int dx[4] = {0, 0, 1, -1};\n int dy[4] = {1, -1, 0, 0};\n\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n n = grid.size();\n m = grid[0].size();\n\n vector<vector<vector<bool>>> visited(n+10, vector<vector<bool>>(m+10, ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n\n// Function for Depth-First Search (DFS) with memoization\nbool dfs(vector<vector<int>>& grid, int x, int y, int health, vector<vector<vector<int>>>& memo) {\n int m = grid.size();\n int n = grid[0].size();\n\n // Base case: if health is less than or equal to zero, ret...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n vector<vector<vector<int>>> memo;\n \n bool helper(int row, int col, int n, int m, vector<vector<int>>& vis, vector<vector<int>>& grid, int health) {\n if (row == n - 1 && col == m - 1) {\n return health > 0;\n }\n \n if (memo[row]...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n vector<vector<vector<int>>> dp;\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n dp.resize(grid.size(), vector<vector<int>>(grid[0].size(), vector<int>(health + 1, -1)));\n\n vector<vector<int>> visited(grid.size(), vector<int>(grid[0].size()));...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n vector<vector<vector<int>>> dp; // Memoization table\n vector<vector<int>> visited; // To track visited cells\n\n bool sol(int row, int col, int n, int m, vector<vector<int>>& grid, int health) {\n if (health <=0) return false; // Not enough health\n if...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int h) {\n int n = grid.size(), m = grid[0].size();\n vector<vector<int>> v(n, vector<int> (m, 1e9));\n queue<vector<int>> q;\n if(grid[0][0] == 0)q.push({0, 0, 0}), v[0][0] = 0;\n else q.push({0,...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n\n typedef long long ll;\n\n vector<vector<ll>>mv = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};\n\n bool findSafeWalk(vector<vector<int>>& grid, int ht) {\n \n ll m = grid.size();\n ll n = grid[0].size();\n\n vector<vector<ll>>st(m, vector<ll>(n, -1))...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n\n typedef long long ll;\n\n vector<vector<ll>>mv = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};\n\n bool findSafeWalk(vector<vector<int>>& grid, int ht) {\n \n ll m = grid.size();\n ll n = grid[0].size();\n\n vector<vector<ll>>st(m, vector<ll>(n, -1))...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\n// public:\n// int f(int i,int j,vector<vector<int>>& g,vector<vector<int>> vis){\n// if(i<0 || j<0 || i>=g.size() || j>=g[0].size()) return 0;\n \n// int dr[4]={0,0,1,-1};\n// int dc[4]={1,-1,0,0};\n \n// vis[i][j]=1;\n// int...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& a, int health) {\n\n int n = a.size();\n int m = a[0].size();\n int v = n * m;\n vector<vector<int>> adj[v];\n\n int delrow[4] = {0, 0, -1, 1};\n int delcol[4] = {-1, 1, 0, 0};\n\n for (in...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size(),n=grid[0].size();\n deque<vector<int>> qu;\n vector<vector<int>> minSum(grid.size(),vector<int>(grid[0].size(),INT_MAX));\n minSum[0][0] = grid[0][0];\n qu.push...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\n vector<vector<int>>vis;\n vector<vector<vector<int>>>dp;\n int m,n;\n bool dfs(vector<vector<int>>& grid, int health, int i, int j) \n {\n // cout<<i<<' '<<j<<' '<<health<<' '<<vis[i][j]<<\" , \";\n // cout<<m<<' '<<n<<\" \\n \";\n if(i<0 || i>=m || j<0 || j...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\nint dir[5]={-1,0,1,0,-1};\n bool dfs(int i,int j,int n,int m,vector<vector<int>>& grid, int health,vector<vector<int>>& vis,vector<vector<vector<int>>> &dp){\n if(health<=0)return false;\n if(i==n-1 && j==m-1)return true;\n if(dp[i][j][health]!=-1)return d...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n\n bool solve(vector<vector<int>>& grid, int n, int m, int i, int j, vector<vector<int>>& vis, vector<vector<vector<int>>>& dp, int h){\n if(i<0 || j<0 || i==n || j == m || h<=0 || vis[i][j] == 1) return false;\n\n if(i==n-1 && j==m-1){\n return h>grid...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "#define pb push_back\n#define ll long long\n#include <bits/stdc++.h>\nusing namespace std;\n\n\nclass Node {\npublic: \n int x, y, health;\n\n Node(int x2, int y2, int h2) {\n x = x2;\n y = y2;\n health = h2;\n }\n};\n\nclass Solution {\npublic:\n bool findSafeWalk(vecto...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "#include \"bits/stdc++.h\"\nclass Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n set<pair<int,vector<int>>> q;\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<int>> vis(n,vector<int>(m,0));\n pair<int,vector<int>> p;...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool isValid(int i, int j , int n , int m ){\n if(i<0||j<0 ||i>=n||j>=m) return false;\n return true;\n }\n bool dfs(vector<vector<int>>& grid, int health, int i, int j, vector<vector<vector<int>>>& memo){\n int n = grid.size() , m = grid[0].size()...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findPath(int i, int j, vector<vector<int>>& grid, int health, vector<vector<vector<int>>>& dp){\n if (grid[i][j] == -1) {\n return false;\n }\n int newHealth = health - grid[i][j];\n if (newHealth <= 0) {\n return false;\...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n // int isPossible(\n // vector<vector<int>>& grid, \n // int health, \n // vector<vector<vector<int>>>& v, \n // vector<vector<vector<int>>>& dp, \n // int m, int n, int i, int j, int oghlt) {\n // // Base cases\n // if (i == (...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n priority_queue<pair<int, pair<int, int>>> pq;\n int n = grid.size();\n int m = grid[0].size();\n int directions[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n pq.push({health - grid...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "#include <vector>\n#include <queue>\nusing namespace std;\n\nclass Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size(), n = grid[0].size();\n vector<vector<int>> directions = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n \n // If the...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size(), n = grid[0].size();\n vector<vector<int>> directions = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n \n queue<pair<pair<int, int>, int>> q;\n vector<vector<int>> visited(m, vector<int...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "#define vi vector<int>\n#define vvi vector<vi>\n#define vvvi vector<vvi>\n\nclass Solution {\npublic:\n int rec(int i, int j, int h, vvi& vec, vvi& vis, vvvi& dp, int n, int m){\n if (i==n-1 && j==m-1) return h>0;\n\n if (h<1) return 0;\n\n if (dp[i][j][h] != -1) return dp[i][j][h];...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "#define vi vector<int>\n#define vvi vector<vi>\n#define vvvi vector<vvi>\n\nclass Solution {\npublic:\n int rec(int i, int j, int h, vvi& vec, vvi& vis, vvvi& dp, int n, int m){\n if (i==n-1 && j==m-1) return h>0;\n\n if (h<1) return 0;\n\n if (dp[i][j][h] != -1) return dp[i][j][h];...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "#include <vector>\n#include <queue>\n\nusing namespace std;\n\nclass Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n = grid.size(), m = grid[0].size();\n vector<vector<int>> directions = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n vector<vector<int...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n=grid.size();\n int m=grid[0].size();\n vector<vector<int>> dirs={{1,0},{-1,0},{0,1},{0,-1}};\n queue<array<int,3>> q;\n q.push({health-grid[0][0],0,0});\n int maxHealt...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\nint f(int i,int j,int health,vector<vector<int>>& grid,vector<vector<int>> &visited,vector<vector<vector<int>>> &dp){\n int m=grid.size();\n int n=grid[0].size();\n if(i==m-1&&j==n-1&&health>1) return true;\n if(i==m-1&&j==n-1&&health==1&&grid[m-1][n-1]==0) return tru...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool rec(vector<vector<int>>& grid, int health , int i ,int j ,vector<vector<int>>& vis , vector<vector<vector<int>>> &dp ){\n if(health <= 0) return false;\n if( i == grid.size()-1 && j == grid[0].size()-1) return grid[i][j] == 0 || (grid[i][j] == 1 && health ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n int hash(int i, int j) {\n return i * 51 + j;\n }\n\n vector<int> dehash(int hash) {\n return { hash / 51, hash % 51 };\n }\n\n void visit(vector<vector<int>>& grid, int hashed, unordered_set<int>& met, queue<int>& q) {\n if (met.find(hashed) ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n = grid.size();\n int m = grid[0].size();\n\n vector<vector<int>> dist(n + 1, vector<int>(m + 1, INT_MAX));\n\n bfs(0, 0, grid, dist);\n\n for (int i = 0; i < n; i++) {\n ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n vector<vector<vector<ll>>> dp;\n bool solve(ll i, ll j, ll k, vector<vector<ll>>& vis, vector<vector<int>>& grid) {\n if(grid[i][j] == 1) k--;\n if(k <= 0) return false;\n if(i == grid.size()-1 && j == grid[0].size()-1) {\n ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n //#define vi vector<int>;\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n = grid.size(), m = grid[0].size();\n //int i = 0, j = 0;\n int dp[health + 2][51][51];\n if(grid[0][0] == 1) health--;\n memset(dp, -1, sizeof(...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\n private:\n unordered_map<string, bool> memo;\n bool dfs(vector<vector<int>>& grid,int row,int col, int health){\n \n int n = grid.size();\n int m = grid[0].size();\n string state = to_string(row) + \",\" + to_string(col) + \",\" + to_string(health);\n...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n vector<int> x = {1,-1,0,0};\n vector<int> y = {0,0,1,-1};\n unordered_map<string, bool> memo;\n\nbool dfs(vector<vector<int>> &grid, int health, int r, int c) {\n if (r < 0 || r >= grid.size() || c < 0 || c >= grid[0].size() || health <= 0 || grid[r][c] == -1) return...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\nprivate:\n int rowCount;\n int colCount;\n int h;\n vector<vector<int>> directions;\n\n vector<vector<int>> dp;\npublic:\n\n bool isInBounds(int r, int c) {\n return r>=0 && r<rowCount && c>=0 && c<colCount;\n }\n\n bool canReachEnd(vector<vector<int>> &grid...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n = grid.size(), m = grid[0].size();\n vector<vector<vector<int>>> memo(n, vector<vector<int>>(m, vector<int>(health + 1, -1)));\n \n stack<tuple<int, int, int>> stk;\n stk.pus...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool recur(int x,int y,vector<vector<int>>& grid,vector<vector<int>> &h,int health){\n int m,n;\n m=grid.size();\n n=grid[0].size();\n \n if(x<0 || y<0 || x==m || y==n || health-grid[x][y]<=h[x][y])\n return false;\n\n heal...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size();\n int n = grid[0].size();\n\n if (m == 0 || n == 0 || (grid[0][0] == 1 && health <= 1)) {\n return false;\n }\n\n // Create a visited array to track...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n #define vi vector<int>\n #define INF 1<<30\n vector<vector<int> > dir = {{-1,0}, {1, 0}, {0, 1}, {0, -1}};\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n auto comp = [](vi v1, vi v2){\n return v1[2] > v2[2];\n };\n prio...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "#include <queue>\n#include <vector>\n#include <tuple>\n\nclass Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int R = grid.size();\n int C = grid[0].size();\n\n // Directions: right, left, down, up\n vector<pair<int, int>> directions = {{0,...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\n map<pair<int,pair<int,int>>,bool>dp;\n bool f(int i,int j,int n,int m,vector<vector<int>>& grid, int health,vector<vector<int>> &vis)\n {\n if(health<=0)\n return false;\n if(i==n-1 && j==m-1)\n {\n \n \n if(health>0)\n ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "#include <vector>\n#include <queue>\n\nclass Solution {\npublic:\n vector<pair<int, int>> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};\n\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size();\n int n = grid[0].size();\n \n // Memoization table to ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size();\n int n = grid[0].size();\n \n \n vector<vector<vector<int>>> memo(m, vector<vector<int>>(n, vector<int>(health + 1, -1)));\n \n \n vector...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size();\n int n = grid[0].size();\n \n // Create a memo table to store visited states (r, c, remaining health)\n vector<vector<vector<int>>> memo(m, vector<vector<int>...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size();\n int n = grid[0].size();\n \n \n vector<vector<vector<int>>> memo(m, vector<vector<int>>(n, vector<int>(health + 1, -1)));\n \n \n vector...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size();\n int n = grid[0].size();\n \n // Direction vectors\n vector<int> dx = {1, 0, -1, 0};\n vector<int> dy = {0, 1, 0, -1};\n \n // Queue for ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n\n\n void traverse(vector<vector<int>>& grid, vector<vector<int>>& path_cost, int health, int i,int j, int max_health, int p, int q){\n if(i<0||j<0||i>=grid.size()||j>=grid[i].size()||path_cost[i][j]<=health+grid[i][j]||health>max_health){\n return ;\n ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n int dp[51][51][101];\n int dir[4][2]={{0,1},{1,0},{-1,0},{0,-1}};\n bool dfs(vector<vector<int>>&g,int x,int y,set<pair<int,int>>& path,int heal){\n int n=g.size(),m=g[0].size();\n if(heal==0) return false;\n if(x==n-1&&y==m-1) return true;\n ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int hp) {\n int H = grid.size();\n int w = grid[0].size();\n \n vector<vector<int>> directions = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };\n \n vector<vector<int>> ans(H, vector<int>(w, INT_MIN...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int been[51][51] = {0};\n\n int M=grid.size(), N=grid[0].size();\n\n vector<vector<int>> data;\n vector<int> temp;\n data.push_back({0, 0, health});\n\n while(data.size()){\...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool rec(vector<vector<int>>& grid, int health,int x,int y,vector<vector<vector<int>>> &dp)\n {\n if(health==0)\n return false;\n int m=grid.size(),n=grid[0].size();\n if(x==m-1 && y==n-1)\n return true;\n if(!dp[x][y][heal...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<int>>maxHealth(n, vector<int>(m,-1));\n queue< vector<int> >q;\n q.push({0,0,health-grid[0][0]});\n while(!q.e...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "bool isvalid(int i, int j, int n, int m){\n return (i>=0 && i < n && j>=0 && j < m);\n}\nclass Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int n = grid.size(), m = grid[0].size();\n vector<vector<int>> dist(n,vector<int>(m,INT_MAX));\n dist...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> dir = {{1,0}, {0,1}, {-1, 0}, {0,-1}};\n vector<vector<vector<int>>> dp; \n bool solve(vector<vector<int>>& grid, int& h, int i, int j){\n if(i < 0 || j < 0 || i >= grid.size() || j >= grid[0].size()){\n return false;\n }\n ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n /* 0 1 2 3 4 5\n 0[[0,1,1,0,0,0],\n 1[1,0,1,0,0,0],\n 2[0,1,1,1,0,1],\n 3[0,0,1,0,1,0]]\n\n h=3->2->1\n\n [[1,1,1,1]]4\n[[0,0,0,1,0,1,0,0,1,0,1,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,1],\n[0,0,0,0,1,0,0,0,1,1,1,1,0,1,1,1,1,0,1,0,0,0,0,0,0,1,0...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\n vector<vector<int>> dir = {{1,0}, {-1,0}, {0,1}, {0,-1}};\n int dp[50][50][101];\npublic:\n bool recure(vector<vector<int>> &grid, int i, int j, int health, int &n, int &m){\n if(health < 1) return 0;\n if(!i && !j) return 1;\n \n if(dp[i][j][health] ...
3,558
<p>You are given an <code>m x n</code> binary matrix <code>grid</code> and an integer <code>health</code>.</p> <p>You start on the upper-left corner <code>(0, 0)</code> and would like to get to the lower-right corner <code>(m - 1, n - 1)</code>.</p> <p>You can move up, down, left, or right from one cell to another ad...
3
{ "code": "class Solution {\npublic:\n bool findSafeWalk(vector<vector<int>>& grid, int health) {\n int m = grid.size(); \n int n = grid[0].size();\n vector<vector<bool>> bVis( m, vector<bool>( n, false ) );\n\n vector<vector<int>> h( m, vector<int>( n, -1 ) );\n queue<vector<int...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
0
{ "code": "class Solution {\n #define pb push_back\n vector<int> a;\n unordered_set<int> pre[401], suf[401];\n int n,k;\n int min_num_of_elements_to_get[128],Left[128],Right[128];\n int num_of_elements_submask_of[128];\n\npublic:\n \n int maxValue(vector<int>& nums, int K) {\n fill(min_n...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
0
{ "code": "class Solution {\n #define pb push_back\n vector<int> a;\n unordered_set<int> pre[401], suf[401];\n int n,k;\n int min_num_of_elements_to_get[128],Left[128],Right[128];\n int num_of_elements_submask_of[128];\n\npublic:\n \n int maxValue(vector<int>& nums, int K) {\n fill(min_n...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
0
{ "code": "class Solution {\npublic:\n bool dp[202][1 << 7];\n vector<int> conL[402], conR[402];\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n dp[0][0] = 1;\n for (int i = 1; i <= n; i++) {\n int x = nums[i - 1];\n for (int cnt = min(i, k) - 1;...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
0
{ "code": "typedef long long ll;\n\n#define pb push_back\n#define sz(x) (int)x.size()\n#define all(x) begin(x),end(x)\n#define lb(x,y) lower_bound(all(x),y)-begin(x)\nclass Solution {\npublic:\n vector<vector<bool>> part(vector<int> arr, int k) {\n int N = sz(arr);\n vector<vector<bool>> dp(k + 1, ve...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
0
{ "code": "#ifdef LOCAL\n #include \"../../../lib/bits.h\"\n #include \"../../../lib/leetcode.h\"\n #include \"../../../lib/debug.h\"\n#else\n #define debug(...) 1\n#endif\n\nusing ll = long long;\n\ntemplate <typename T>\nstruct PairHash {\n size_t operator() (const pair<T, T>& v) const {\n return hash<size_...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
0
{ "code": "#ifdef LOCAL\n #include \"../../../lib/bits.h\"\n #include \"../../../lib/leetcode.h\"\n #include \"../../../lib/debug.h\"\n#else\n #define debug(...) 1\n#endif\n\nusing ll = long long;\n\ntemplate <typename T>\nstruct PairHash {\n size_t operator() (const pair<T, T>& v) const {\n return hash<size_...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
0
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& v, int k) {\n int n=v.size();\n vector<vector<int>>isPos(k+1,vector<int>(128));\n isPos[0][0]=1;\n vector<vector<int>>pre(n),suf(n);\n\n for(int i=0;i<n;i++)\n {\n for(int tk=k-1;tk>=0;tk--)\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
0
{ "code": "class Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n int n = nums.size();\n char dp[n][k][128], ep[n][k][128];\n memset(dp, 0, sizeof(dp));\n memset(ep, 0, sizeof(ep));\n int res = 0;\n\n dp[0][0][nums[0]] = 1;\n\n for (int i = 1; i < n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
1
{ "code": "class Solution {\npublic:\n typedef bitset<129> bt; // bitset of size 129 (0 to 128)\n \n int maxValue(vector<int>& nums, int d) {\n int n = nums.size();\n \n // Create the dp array\n vector<vector<bt>> dp1(n+1, vector<bt>(d+1));\n vector<vector<bt>> dp2(n+2, ve...