id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "#define pii pair<int,int> \nclass Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int n = matrix.size();\n int m = matrix[0].size();\n map<int,vector<pii>> num;\n vector<vector<int>> dp(n, vector<int>(m, 1));\n for (int i = 0; i < n; i+...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int n=matrix.size(),m=matrix[0].size();\n vector<vector<int>> dp(n,vector<int>(m,1));\n priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> pq;\n for(int i=0;i<n;i++)\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int n=matrix.size(),m=matrix[0].size();\n vector<vector<int>> dp(n,vector<int>(m,1));\n priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> pq;\n for(int i=0;i<n;i++)\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\n using Node = std::pair<int, int>;\n using Nodes = std::vector<Node>;\n using NodesQueue = std::queue<Node>;\n template <typename T>\n using NodeTo = std::vector<std::vector<T>>;\n NodeTo<Nodes> revAdjList;\n NodeTo<int> outDegrees;\n NodeTo<int> maxDist;\n Node...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\nbool isvalid(int i, int j, int n, int m){\n return (((i>=0)&&(i<n))&&((j>=0)&&(j<m)));\n}\n int dfs(int i, int j,vector<vector<int>>& matrix,vector<vector<int>>&dp){\n int ans=0;\n int n=matrix.size();\n int m=matrix[0].size();\n if(dp[i]...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>>dp;\n int n,m;\n vector<pair<int,int>>find_smaller(int i,int j,vector<vector<int>>& matrix)\n {\n vector<pair<int,int>>a;\n if(i>0 && matrix[i][j]>matrix[i-1][j])\n a.push_back({i-1,j});\n if(j>0 && matrix[i][j]>matr...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "\nint MAX(vector<int> V) {\n int res = INT_MIN;\n for (int i = 0; i < V.size(); i++) {\n res = max(V[i], res);\n }\n return res;\n}\n\n\n\nclass Solution {\npublic:\n int solve(vector<vector<int>>& matrix,vector<vector<int>>&dp,int i,int j){\n if(dp[i][j]>= 0){\n ret...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "\nint MAX(vector<int> V) {\n int res = INT_MIN;\n for (int i = 0; i < V.size(); i++) {\n res = max(V[i], res);\n }\n return res;\n}\n\n\n\nclass Solution {\npublic:\n int solve(vector<vector<int>>& matrix,vector<vector<int>>&dp,int i,int j){\n if(dp[i][j]> 0){\n retu...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "\nint MAX(vector<int> V) {\n int res = INT_MIN;\n for (int i = 0; i < V.size(); i++) {\n res = max(V[i], res);\n }\n return res;\n}\n\n\n\nclass Solution {\npublic:\n int solve(vector<vector<int>>& matrix,vector<vector<int>>&dp,int i,int j){\n if(dp[i][j]>= 0){\n ret...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "\nint MAX(vector<int> V) {\n int res = INT_MIN;\n for (int i = 0; i < V.size(); i++) {\n res = max(V[i], res);\n }\n return res;\n}\n\n\n\nclass Solution {\npublic:\n int solve(vector<vector<int>>& matrix,vector<vector<int>>&dp,int i,int j){\n if(dp[i][j]>= 0){\n ret...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n bool isValid(int i, int j, vector<vector<int>> &matrix) {\n int n = matrix.size();\n int m = matrix[0].size();\n return (i >= 0 && i < n && j >= 0 && j < m);\n }\n\n int solve(int i, int j, vector<vector<int>> &dis, vector<vector<int>> &matrix) {\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n\n struct pos {\n int i;\n int j;\n int depth;\n };\n\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int n = matrix.size();\n int m = matrix[0].size();\n\n vector<vector<int>> dp(n, vector<int>(m, 1));\n\n fo...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\n int dfs(vector<vector<int>>& matrix, int row, int col, vector<vector<int>>& cache, vector<vector<int>>& directions)\n {\n if(cache[row][col] != -1) return cache[row][col];\n\n int path = 0;\n for(auto dir : directions)\n {\n int newRow = row +...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int _longestIncreasingPath(vector<vector<int>>& matrix, int r, int c, vector<vector<int>>& dp) {\n static vector<vector<int>> DIRS = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n int m = matrix.size();\n int n = matrix[0].size();\n\n if (dp[r][c] != -1)\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\nprivate: \n int m,n;\n vector<vector<int>> dir = {{0, 1},{0, -1},{1, 0},{-1, 0}};\n vector<vector<int>> memo;\n int dfs(vector<vector<int>>& matrix, int i, int j) {\n if(memo[i][j] != -1) return memo[i][j];\n int ans=1; // start with 1 length;\n for(auto d...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> mat={{0,1},{0,-1},{1,0},{-1,0}};\n int fun(int i,int j,vector<vector<int>> &grid,vector<vector<int>> &dp)\n {\n if(dp[i][j]!=-1)\n return dp[i][j];\n int l=0;\n for(auto it:mat)\n {\n if(i+it[0]>=0 && i+i...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int dfs(int i, int j, vector<vector<int>>& matrix, vector<vector<int>>& lip, vector<vector<bool>>& visited){\n vector<pair<int,int>> dirs={{0,1},{0,-1},{1,0},{-1,0}};\n if(i<0 || i>=matrix.size() || j<0 || j>=matrix[0].size()){\n return 0;\n }\...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "int dfs(int i, vector<vector<int>> &v, vector<int> &visit, map<int,int> &arr){\n if(visit[i]){\n return arr[i];\n }\n visit[i] = 1;\n int ans = 0;\n for(auto j:v[i]){\n ans = max(ans, dfs(j,v,visit,arr));\n }\n ans++;\n arr[i] = max(arr[i], ans);\n return ans;\n}\ni...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int ROWS;\n int COLS;\n vector<vector<int>> dir = {{0, 1},{0, -1},{1, 0},{-1, 0}};\n vector<vector<int>> matrix;\n\n int dfs(int r, int c, vector<vector<int>> &dp) {\n if (dp[r][c] != -1) return dp[r][c];\n dp[r][c] = 0; // visiting\n int ans ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n\n int dfs(int r_idx, int c_idx, vector<vector<int>>& matrix, vector<vector<bool>>& visited, vector<vector<int> > &m_height) {\n visited[r_idx][c_idx] = true;\n int curr_height = 0;\n for(pair<int, int> neighbour: getNeighbours(r_idx, c_idx, matrix)) {\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> saved_res;\n\n int longest_path_from_source(vector<vector<int>>& matrix, int row, int col) {\n list<int> paths;\n if (row - 1 >= 0) {\n if (matrix[row][col] < matrix[row-1][col]){\n if (saved_res[row-1][col] != -1...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int dfs(int i,int j,vector<vector<int>>& matrix,vector<vector<int>>& dp){\n if(i<0||j<0||i>=matrix.size()||j>=matrix[0].size()){\n return 0;\n }\n if(dp[i][j]!=-1)return dp[i][j];\n int res=1;\n if(i+1<matrix.size() && matrix[i+1]...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n unordered_map<int, int> maxLengthAt;\n\n int getMaxLength(vector<vector<int>>& matrix, int pos) {\n if (maxLengthAt.find(pos) != maxLengthAt.end()) return maxLengthAt[pos];\n\n int m = matrix.size(), n = matrix[0].size();\n int i = pos / n, j = pos % n...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int calculate(vector<vector<int>>& matrix, vector<vector<int>>& visited, int i, int j, int m, int n) {\n \n if(visited[i][j] != -1)\n return visited[i][j];\n int curr = matrix[i][j];\n int up = 0;\n int down = 0;\n int left...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\ntypedef map<pair<int,int>,vector<pair<int,int>>>GRAPH;\nbool isvalid(vector<vector<int>>& matrix , int row , int col ,int item){\n\tif(row < 0 || row==matrix.size())return false;\n\tif(col < 0 || col==matrix[0].size())return false;\n\tif(matrix[row][col]<=item)return false;\n\tre...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector< vector< int > > memoi;\n Solution() {\n const int N = 205;\n memoi = vector< vector< int > >(N, vector< int >(N, -1));\n }\n\n int findLIP(vector<vector<int>>& matrix, int x, int y) {\n int n = matrix.size();\n int m = matrix[0].si...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector<pair<int,int>> v[200][200] ;\n vector<pair<int,int>> p[200][200] ;\n void dfs(int i, int j ,vector<vector<int>>&vis,vector<pair<int,int>>&topo ){\n if(vis[i][j])return ;\n vis[i][j] = 1 ;\n for(pair<int,int> child : v[i][j]){\n df...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\n int func(vector<vector<int>> &mm,int x,int y,vector<vector<int>> &dp,int m,int n){\n vector<int> dir={-1,0,1,0,-1};\n if(dp[x][y]!=-1)\n return dp[x][y];\n\n int ans=0;\n for(int i=0;i<4;i++){\n int a=min(m-1,max(0,x+dir[i]));\n int b=min(n-1,max(0,y+dir[i+...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n void dfs(int ind,vector<vector<int>>&v,vector<bool>&visit,vector<int>&v1)\n {\n visit[ind] = 1;\n for(auto k1 : v[ind])\n {\n if(!visit[k1])\n {\n dfs(k1,v,visit,v1);\n }\n }\n v1.push_back(...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& a) {\n int n = a.size();\n int m = a[0].size();\n vector<vector<int>> graph(n * m);\n vector<vector<int>> par(n * m);\n vector<int> indegree(n * m , 0);\n for(int i = 0; i<n; i++){\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n map<pair<int, int>, int> memo;\n int helper(vector<vector<int>>& matrix, int x, int y, int prev) {\n if (memo.count(make_pair(x * matrix[0].size() + y, prev))) return memo[make_pair(x * matrix[0].size() + y, prev)];\n if (x >= matrix.size() || x < 0 || y >= m...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n map <pair<int,int>,int> cache;\n int backtrack(int r,int c, int prevNum,vector<vector<int>>& matrix) {\n if (r < 0 || c < 0 || r>=matrix.size()||c>= matrix[0].size() || matrix[r][c] <= prevNum) {\n return 0;\n }\n if (cache.find({r,c}) !=cac...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "vector<vector<int>> dirs{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n\nclass Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int n = matrix.size(), m = matrix[0].size(), ans = 1;\n vector<vector<int>> freq(n, vector<int>(m, 1)), vis(n, vector<int>(m, 0));\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n bool isValid(int i, int j, int n, int m){\n return (i>=0 && j>=0 && i<n && j<m);\n }\n int dfs(int i, int j, vector<vector<int>>& matrix, vector<vector<int>>& dp){\n vector<int> dx = {-1,0,1,0};\n vector<int> dy = {0,-1,0,1};\n\n if(dp[i][j] ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n\n int dfs(int r, int c, vector<vector<int>>& matrix, vector<vector<int>> &dp) {\n \n int m = matrix.size();\n int n = matrix[0].size();\n vector<int> dr = {0, +1, 0, -1};\n vector<int> dc = {+1, 0, -1, 0};\n\n if(dp[r][c] != -1){\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int find(int r,int c,vector<vector<int>>&matrix,vector<vector<int>>&dp,int n,int m)\n {\n vector<int>delr={-1,0,1,0};\n vector<int>delc={0,1,0,-1};\n\n if(dp[r][c]!=-1)\n {\n return dp[r][c];\n }\n for(int i=0;i<4;i++)\n...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "// https://leetcode.com/problems/longest-increasing-path-in-a-matrix/\n\n/*\n * The problem is asking for the longest path.\n * \t\tWe learned before, the longest path is efficiently solvable in DAG\n *\n * We also, know the matrix can be represented as a graph?\n *\n * Let's analyze it 2 neighbor cells\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n // convert the indices for 2d matrices to 1d flat arrays\n pair<int,int> i2d(int rows, int cols, int n){\n return { (int)(n/cols) , (int)(n%cols) };\n }\n\n int i1d(int rows, int cols, int i, int j){\n return j + i*cols;\n }\n\n // function to get...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n\n int dfs(vector<vector<int>>& matrix, vector<vector<int>>& dp, int row, int col)\n {\n vector<int> dr{0, 0, -1, 1};\n vector<int> dc{1, -1, 0, 0};\n \n // visited[row][col] = true; \n if(dp[row][col] != 0)\n return dp[row][c...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>>dp;\n bool checkPath(vector<vector<int>>&matrix, int x, int y, int prevx, int prevy)\n {\n if(prevx >= matrix.size() || prevx < 0 || prevy >= matrix[0].size() || prevy < 0)\n return 0;\n \n if(matrix[x][y] >= matrix[pre...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "const std::vector<std::pair<int, int>> dirs = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};\n\nclass Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n vector<vector<int>> path_size(matrix.size(), vector<int>(matrix[0].size()));\n int result = 0;\n for (int i = 0...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n const vector<vector<int>> dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n\n map<pair<int,int>,int> mp;\n int search(int x, int y){\n if(mp.find({x,y})!=mp.end()) return mp.at({x,y});\n int ans =1;\n for(const vector<int> dir: dirs){\n int n...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n // Do a topological sort\n // Go through that st that last incoming edge in toposort is the path considered and find length of max length\n int n=matrix.size(), m=matrix[0].size();\n vector...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n map<pair<int,int>,int>m1;\n set<vector<int>> s1;\n for(int i=0;i<matrix.size();i++){\n for(int j=0;j<matrix[0].size();j++){\n s1.insert({matrix[i][j],i,j});\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\nvector<bool> visited;\nvector<int> most;\nvector<vector<int>> adj;\n\nint visit(int index)\n{\n cout<<\"visit \"<<index<<endl;\n if (visited[index]) return most[index];\n visited[index]=true;\n for (int i : adj[index])\n {\n most[index]=max(most[index], visit(i)+1);\...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\n const vector< vector<int> > directions = {{1,0}, {-1, 0}, {0,1}, {0,-1}};\n int dfs(vector<vector<int>>& matrix, int i, int j, int n, int m, vector<vector<int>> &dp) {\n if(dp[i][j]!=0) {\n return dp[i][j];\n } \n for(auto dir: directions) {\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n\n vector<vector<int>> moves{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};\n\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int rows = matrix.size(), cols = matrix[0].size(), result = 0;\n vector<vector<int>> dp(rows, vector<int>(cols, 0));\n stack<v...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n\n //dp[r][c] represents len of longest incr path starting at r, c\n vector<vector<int>> dp(m, vector<int>(n, 0));\n\n //fill in d...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n\n //dp[r][c] represents len of longest incr path starting at r, c\n vector<vector<int>> dp(m, vector<int>(n, 0));\n\n //fill in d...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};\n int dy[8] = {0, -1, 0, 1, -1, 1, -1, 1};\n int n,m,ans=1;\n queue<pair<pair<int,int>,int>>q;\n map<pair<int,int>,vector<pair<int,int>>>mp;\n map<pair<int,int>,int>in;\n void topo(){\n while (!q.empty()){\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>>validNeigh(vector<vector<int>>&matrix, int i, int j, int m,int n){\n vector<vector<int>> res;\n int curr = matrix[i][j];\n if(i>0 && matrix[i-1][j] > curr){\n res.push_back({i-1,j});\n }\n if(j>0 && matrix[...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\nint longestIncreasingPath(vector<vector<int>>& matrix) {\n\n int m = matrix.size();\n int n = matrix[0].size();\n\n vector<vector<int>> G( m * n);\n vector<int> out(m * n);\n vector<int> ans(m * n);\n\n for(int i = 0 ; i < m;i++){\n for(int j=0;j < n;j++)...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n priority_queue<vector<int> > pq;\n for(int i=0;i<matrix.size();i++){\n for(int j=0;j<matrix[0].size();j++){\n pq.push({-1*matrix[i][j],i,j});\n }\n }\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\n vector<vector<int>> dp;\n vector<vector<bool>> vis;\npublic:\n vector<vector<int>> getvert(int i, int j, vector<vector<int>> &matrix){\n vector<vector<int>> ans;\n int m = matrix.size();\n int n = matrix[0].size();\n if(i < m-1 and matrix[i+1][j] > ma...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int sides[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n map<pair<int, int>, vector<int>> graph;\n map<pair<int, int>, int> dep_count;\n\n for (int i = 0; i < matrix.size(); i++) {\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int sides[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n map<pair<int, int>, vector<int>> graph;\n map<pair<int, int>, int> dep_count;\n\n for (int i = 0; i < matrix.size(); i++) {\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int sides[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n map<pair<int, int>, vector<int>> graph;\n map<pair<int, int>, int> dep_count;\n\n for (int i = 0; i < matrix.size(); i++) {\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> directions = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int m = matrix.size();\n if (m == 0) return 0;\n int n = matrix[0].size();\n \n // In-degree matrix to kee...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> directions = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int m = matrix.size();\n if (m == 0) return 0;\n int n = matrix[0].size();\n \n // In-degree matrix to kee...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic: \n\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n vector<vector<int>> dirs={{-1,0},{0,-1},{1,0},{0,1}};\n \n int n=matrix.size();\n int m=matrix[0].size();\n vector<vector<int>> indegree(n,vector<int>(m));\n for(int i=0;i<...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector<pair<int, int>> moves = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n bool check(int x, int y, int n, int m) {\n return (x >= 0 && x < n) && (y >= 0 && y < m);\n }\n int longestIncreasingPath(vector<vector<int>>& a) {\n int n = a.size(), m = a[0].size();...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int m=matrix.size();\n int n=matrix[0].size();\n map<pair<int,int>,vector<pair<int,int>>> adj;\n int dx[4]={-1,0,1,0};\n int dy[4]={0,-1,0,1};\n map<pair<int,int>,int> indegre...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int longestIncreasingPath(vector<vector<int>>& matrix) {\n int n = matrix.size(), m = matrix[0].size();\n vector<vector<int>> dirs = {{0,1}, {0,-1}, {1,0}, {-1,0}};\n\n vector<vector<int>> len(n, vector<int>(m)), indeg(n, vector<int>(m));\n for(int...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n int dirX[4] = {1,-1,0,0};\n int dirY[4] = {0,0,-1,1};\n\n vector<vector<int>> dp;\n int dfs(vector<vector<int>>&matrix, int startX, int startY){\n if(dp[startX][startY])return dp[startX][startY];\n int ans = 1;\n for(int i = 0;i<4;i++){\n ...
329
<p>Given an <code>m x n</code> integers <code>matrix</code>, return <em>the length of the longest increasing path in </em><code>matrix</code>.</p> <p>From each cell, you can either move in four directions: left, right, up, or down. You <strong>may not</strong> move <strong>diagonally</strong> or move <strong>outside t...
3
{ "code": "class Solution {\npublic:\n vector<pair<int, int>> directions{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n\n int longestIncreasing(int i, int j, vector<vector<int>>& matrix, vector<vector<int>>& dp){\n if (dp[i][j] != -1){\n return dp[i][j];\n }\n int n = matrix.size();\n ...
330
<p>Given a sorted integer array <code>nums</code> and an integer <code>n</code>, add/patch elements to the array such that any number in the range <code>[1, n]</code> inclusive can be formed by the sum of some elements in the array.</p> <p>Return <em>the minimum number of patches required</em>.</p> <p>&nbsp;</p> <p><...
1
{ "code": "class Solution {\npublic:\n int minPatches(vector<int>& nums, int n) {\n long range = 1;\n int numberOfPatches = 0;\n\n for (int i = 0; i < nums.size(); i++) {\n if (range > n) {\n break;\n }\n if (range < nums[i]) {\n c...
330
<p>Given a sorted integer array <code>nums</code> and an integer <code>n</code>, add/patch elements to the array such that any number in the range <code>[1, n]</code> inclusive can be formed by the sum of some elements in the array.</p> <p>Return <em>the minimum number of patches required</em>.</p> <p>&nbsp;</p> <p><...
1
{ "code": "class Solution {\npublic:\n int minPatches(vector<int>& nums, int n) {\n long long miss = 1;\n int result = 0;\n int i = 0;\n\n while (miss <= n) {\n if (i < nums.size() && nums[i] <= miss) {\n miss += nums[i];\n i++;\n } el...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "// fm-vo\nclass Node {\npublic:\n Node* child[26] = {NULL};\n bool isEndOfWord;\n Node(){\n this->isEndOfWord = false;\n }\n};\n\nclass Trie {\npublic:\n Node* head;\n Trie(){\n head = new Node();\n }\n\n void addWord(string st) {\n Node* temp = head;\n f...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Trie {\npublic:\n vector<Trie*> child;\n bool isend;\nTrie(){\n this->child.resize(26,nullptr);\n this->isend=false;\n }\n void insert(string &s){\n auto head = this;\n for(auto &x:s){\n if(head->child[x-'a']==nullptr){\n Trie *child =...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\nprivate:\n struct TrieNode{\n unordered_map<int, TrieNode*> child;\n bool isWord = false;\n string word = \"\";\n };\n TrieNode* root = new TrieNode(); \n vector<string> outs;\n int C;\n int R;\n\n\npublic:\n void insert(string &word) {\n T...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n vector<string> findWords(vector<vector<char>>& board,\n vector<string>& words) {\n root_ = new Node();\n BuildTrie(words);\n int n = board.size();\n int m = board[0].size();\n unordered_set<string> ans;\n f...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\n struct TrieNode {\n char ch;\n bool leaf;\n std::vector<std::shared_ptr<TrieNode>> children;\n\n explicit TrieNode(char c) : ch(c), leaf(false), children(26, nullptr) {}\n };\n\n std::shared_ptr<TrieNode> ConstructTree(const std::vector<std::string> &...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n int n = -1;\n int m = -1;\n vector<vector<char>> ext_board;\n vector<vector<int>> base;\n vector<vector<int>> cur;\n\n bool stupidCases = false;\n vector<string> findWords(vector<vector<char>>& board, vector<string>& words) {\n vector<string> res;\n ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Node {\n vector<Node*> children;\n int idx;\n bool ends = false;\npublic:\n Node () {\n vector<Node*> temp(26, NULL);\n children = temp;\n idx = -1;\n }\n\n bool isPresent(char ch) {\n return children[ch-'a'] != NULL;\n }\n\n void createChild(char c...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class TrieNode {\npublic:\n vector<TrieNode*> child;\n bool isEnd;\n TrieNode() {\n for (int i = 0; i < 26; i++) {\n child.push_back(NULL);\n }\n isEnd = false;\n }\n};\n\nclass Solution {\n TrieNode *root;\n set<string> ans;\n vector<pair<int, int>> nbr...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n class Node{\n public:\n vector<Node* > children;\n bool eow=false;\n\n Node(){\n for(int i=0; i<26; i++) children.push_back(nullptr);\n }\n };\n void dfs(vector<vector<char>>& board, Node* root1, set<stri...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Node {\npublic:\n vector<Node*> children;\n char c;\n bool isEnd;\n\n Node(char cc) {\n c = cc;\n isEnd = false;\n\n for(int i = 0; i < 26; i ++) {\n children.push_back(nullptr);\n }\n }\n\n Node* addChild(char cc) {\n children[cc - 'a']...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n struct TrieNode {\n vector<shared_ptr<TrieNode>> children;\n bool isEnd{false};\n\n TrieNode() {\n for (int i = 0; i < 26; i++) {\n children.push_back(nullptr);\n }\n }\n };\n\n void insertTrie(shared_ptr<...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n struct TrieNode {\n vector<shared_ptr<TrieNode>> children;\n bool isEnd{false};\n\n TrieNode() {\n for (int i = 0; i < 26; i++) {\n children.push_back(nullptr);\n }\n }\n };\n\n void insertTrie(shared_ptr<...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n struct TrieNode {\n vector<shared_ptr<TrieNode>> children;\n bool isEnd{false};\n\n TrieNode() {\n for (int i = 0; i < 26; i++) {\n children.push_back(nullptr);\n }\n }\n };\n\n void insertTrie(shared_ptr<...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n struct TrieNode {\n vector<shared_ptr<TrieNode>> children;\n bool isEnd{false};\n\n TrieNode() {\n for (int i = 0; i < 26; i++) {\n children.push_back(nullptr);\n }\n }\n };\n\n void insertTrie(shared_ptr<...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "// struct cNode {\n// char val;\n// bool isEnd;\n// string word;\n// unordered_map<char, cNode*> children;\n// };\n\n// class Trie {\n// public:\n// cNode* root;\n \n// Trie() {\n// root = new cNode();\n// }\n\n// void add(string s) {\n// cNode* cur = ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution\n{\npublic:\n\tvoid deepDFS\n\t\t(const vector<vector<char>>& B, \n\t\t\tunordered_map<int, unordered_map<int, unordered_set<string>>>& F,\n\t\t\t\tunordered_map<string, unordered_set<int>>& G,\n\t\t\t\t\tvector<vector<int>>& V, int maxDepth, int depth, \n\t\t\t\t\t\tstring& s, int x, int y,...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution\n{\npublic:\n\tvoid deepDFS\n\t\t(const vector<vector<char>>& B, \n\t\t\tunordered_map<int, unordered_map<int, unordered_set<string>>>& F,\n\t\t\t\tunordered_map<string, unordered_set<int>>& G,\n\t\t\t\t\tvector<vector<int>>& V, int maxDepth, int depth, \n\t\t\t\t\t\tstring& s, int x, int y,...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n int tr[30003 * 10][26];\n int cnt[30003], idx = 0;\n int m, n;\n string ma[10003];\n int dirs[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n vector<string> res;\n\n // int visited[12][12];\n void ins(string word)\n {\n int p = 0;\n for (c...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "#define MAXNODES 300000\n\nclass Solution {\npublic:\n struct Node {\n static inline int nxt = 0;\n bool isLeaf;\n int children[26];\n\n Node() : isLeaf(false) {\n fill(children, children+26, 0);\n }\n\n int get(char c) { return children[c-'a']; }\n\n...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n vector<vector<char>> board;\n map<char, vector<pair<int,int>>> mp;\n vector<pair<int,int>> path;\n vector<vector<pair<int,int>>> coords;\n\n bool test_rest(int index){\n for (int i=index; i<coords.size(); i++){\n for (pair<int,int>p:coords[i]){\n...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\nprivate:\n int trie[300005][26];\n bool stop[300005];\n int node_count;\n\n void insert(const string& word){\n int node = 0;\n for(char c: word){\n if(trie[node][c-'a'] == 0) {\n trie[node][c-'a'] = ++node_count;\n }\n ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": " \nclass Solution {\npublic:\n// #include<bits/stdc++.h>\n// using namespace std;\n\nint node,trie[300001][26],cnt[300001];\nmap<int, string>vec;\nvoid insert(vector<string>&words)\n{\n for(int i=0;i<words.size();i++)\n {\n int val=0,val1;\n for(auto itr:words[i])\n {\n ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "struct TrieNode {\n string word = \"\";\n unordered_map<char, TrieNode*> letters;\n};\n\nclass Solution {\npublic:\n vector<vector<int>> directions = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n vector<vector<char>> board;\n\n vector<string> findWords(vector<vector<char>>& board, vector<string>& wo...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n struct TrieNode{\n TrieNode * next[256] = {0};\n bool is_leaf = false;\n string word;\n\n TrieNode() {;};\n };\n\n class Trie{\n public:\n TrieNode * root;\n\n Trie(){\n root = new TrieNode();\n };\n\n ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Node {\npublic:\n int count;\n char ch;\n Node*prv=nullptr;\n unordered_map<char,Node*>child;\n\n Node(): count(0), ch('#'){}\n Node(char ch): count(0), ch(ch){}\n Node(char ch, Node*prv): count(0), ch(ch),prv(prv){}\n};\n\n\n\nclass Trie {\npublic:\n Node* root;\n\n Trie()...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n int x[4] = {0, 1, 0, -1};\n int y[4] = {1, 0, -1, 0};\n struct TreeNode\n {\n char c;\n int index;\n unordered_map<char, TreeNode*> children;\n TreeNode(char val) {c = val;}\n };\n\n TreeNode *root;\n int m, n, k;\n vector<vect...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n int x[4] = {0, 1, 0, -1};\n int y[4] = {1, 0, -1, 0};\n struct TreeNode\n {\n char c;\n int index;\n unordered_map<char, TreeNode*> children;\n TreeNode(char val) {c = val;}\n };\n\n TreeNode *root;\n int m, n, k;\n vector<vect...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n int n = -1;\n int m = -1;\n vector<vector<char>> ext_board;\n vector<vector<vector<int>>> base;\n vector<vector<vector<int>>> cur;\n int i_cur = 0;\n\n bool stupidCases = false;\n vector<string> findWords(vector<vector<char>>& board, vector<string>& words...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution\n{\npublic:\n\tvoid deepDFS\n\t\t(const vector<vector<char>>& B, \n\t\t\tunordered_map<int, unordered_map<int, unordered_set<string>>>& F,\n\t\t\t\tunordered_map<string, unordered_set<int>>& G,\n\t\t\t\t\tvector<vector<int>>& V, int maxDepth, int depth, \n\t\t\t\t\t\tstring& s, int x, int y,...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution\n{\npublic:\n\tvoid deepDFS\n\t\t(const vector<vector<char>>& B, \n\t\t\tunordered_map<int, unordered_map<int, unordered_set<string>>>& F,\n\t\t\t\tunordered_map<string, unordered_set<int>>& G,\n\t\t\t\t\tvector<vector<int>>& V, int maxDepth, int depth, \n\t\t\t\t\t\tstring& s, int x, int y,...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\n\nclass Trie{\nprivate:\n int v;\n int pv;\n vector<Trie* > children; \n\npublic:\n Trie() : v(0), pv(0), children(26) {}\n\n void insert(const string& word){\n Trie *root = this;\n for ( int i = 0; i < word.length(); i++ ){\n int idx = word[i] - 'a...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\n\nclass Trie{\nprivate:\n int v;\n int pv;\n vector<Trie* > children; \n\npublic:\n Trie() : v(0), pv(0), children(26) {}\n\n void insert(const string& word){\n Trie *root = this;\n for ( int i = 0; i < word.length(); i++ ){\n int idx = word[i] - 'a...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class TrieNode{\npublic:\n bool end_ = false;\n bool emplaced_ = false;\n unordered_map<char, TrieNode*> next_;\n};\n\nclass Trie{\npublic:\n TrieNode* root_ = new TrieNode();\n\n void insert(const string& word){\n TrieNode* cur = root_;\n for (int i = 0; i < word.size(); ++i){\n if (!cur->...