id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(const std::vector<int>& stones) {\n std::vector<std::vector<char>> memo(stones.size()+1, std::vector<char>(stones.size()+1, -1));\n return go(stones, 0, 0, memo);\n }\n\nprivate:\n bool go(const auto& stones, int idx, long speed, auto& memo) {\n if(idx ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n\n int target;\n vector<map<int,bool>> mp;\n bool rec(set<int> &s, int j, int cv){\n if(j == 0) return false;\n if(cv > target) return false;\n if(cv == target) return true;\n if(s.find(cv) == s.end()) return false;\n if(mp[j].find... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n int n = stones.size();\n map<int, set<int>> dp;\n dp[stones[0] + 1] = {1}; // can get to dp[] from #'s in set\n for (int i = 1; i < n; ++i){\n // if (dp.find(stones[i]) == dp.end()) continue;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\n map<vector<int>,int>dp;\n int find(int node,vector<int>&v,int last)\n {\n if(node+1==v.size()) return 1;\n if(dp.find({node,last})!=dp.end()) return dp[{node,last}];\n int p=0;\n int n=v.size();\n int st=node+1;\n int en=v.size()-1;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\n map<vector<int>,int>dp;\n int find(int node,vector<int>&v,int last)\n {\n if(node+1==v.size()) return 1;\n if(dp.find({node,last})!=dp.end()) return dp[{node,last}];\n int p=0;\n int n=v.size();\n int st=node+1;\n int en=v.size()-1;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\nbool ok=false;\n int dp[2001][10001];\n bool f(int i,int k,vector<int>& a){\n\n if(i>=a.size()-1){\n dp[i][k]=true;ok=true;return true;\n }\n if(dp[i][k]!=-1)return dp[i][k];\n bool x1=false,x2=false,x3=false;\n auto it=lower_bo... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "using ll = long long;\nclass Solution {\npublic:\n int dp[2005][10000];\n unordered_map<int,int> mpp;\n bool rec(int lvl, int k, vector<int> &nums){\n // pruning\n if(k <= 0)\n return false;\n\n // base case\n if(lvl >= nums.size()-1){\n return tru... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool generate(const vector<int> &stones, int i, int k)\n {\n if (i == (stones.size() - 1))\n {\n return true;\n }\n bool flag = false;\n for (int j = i + 1; j != stones.size(); ++j)\n {\n if ((stones[j] - ston... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool generate(const vector<int> &stones, int i, int k)\n {\n if (i == (stones.size() - 1))\n {\n return true;\n }\n bool flag = false;\n for (int j = i + 1; j != stones.size(); ++j)\n {\n if ((stones[j] - ston... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n unordered_map<int, short> si;\n vector<int> s;\n int n;\n vector<vector<short>> dp;\n\n short jumpable(int from, int jump) {\n if(s[from] + jump == s[n-1])\n return 1;\n if(jump == 0 || (s[from] + jump > s[n-1]))\n return 0;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool rec(int index,int k,vector<int>&stones,map<int,int>&mp,map<vector<int>,bool>&dp){\n if(index==stones.size()-1) return true;\n if(dp.find({index,k})!=dp.end()) return dp[{index,k}];\n bool ans=false;\n for(int i=k-1;i<=k+1;i++){\n if... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n int stlast = stones.back();\n map<int,set<int>> mp;\n int n = stones.size();\n for(int i=0;i<n;i++){\n set<int> s1;\n mp[stones[i]] = s1;\n }\n mp[0].insert(1);\n for... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(const std::vector<int>& stones) {\n std::vector<std::vector<std::optional<bool>>> memo(stones.size()+1, std::vector<std::optional<bool>>(stones.size()+1));\n return go(stones, stones.cbegin(), 0, memo);\n }\n\nprivate:\n bool go(const auto& stones, std::ve... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(const std::vector<int>& stones) {\n std::vector<std::vector<std::optional<bool>>> memo(stones.size()+1, std::vector<std::optional<bool>>(stones.size()+1));\n return go(stones, stones.cbegin(), 0, memo);\n }\n\nprivate:\n bool go(const auto& stones, std::ve... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n unordered_map<int, unordered_map<int, bool>> ikMapping;\n unordered_map<int, unordered_map<int, bool>> ikVis;\n bool rec(vector<int>& s, int i, int k)\n {\n int n = s[i]+k;\n if(ikVis[i][k]) return ikMapping[i][k];\n //cout<<i<<\" \"<<k<<\" \"<<n... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n #define ll long long\n\n bool solve(vector<int>&stones, int index, int k, unordered_map<int,int>&mp, vector<vector<int>>&dp){\n if(index == stones.size()-1) return true;\n if(index >= stones.size()) return false;\n\n if(dp[index][k] != -1) return dp[in... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n #define ll long long\n\n bool solve(vector<int>&stones, int index, int k, unordered_map<int,int>&mp, vector<vector<int>>&dp){\n if(index == stones.size()-1) return true;\n if(index >= stones.size()) return false;\n\n if(dp[index][k] != -1) return dp[in... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n int n = stones.size();\n // vector<unordered_set<long long>> dp(n);\n // dp[0].insert(0);\n // for(int i = 1; i < n; ++i){\n // for(int j = 0; j < i; ++j){\n // long long diff = stone... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool solve(int idx, int prevJump, vector<vector<int>>& dp,\n vector<int>& stones) {\n int n = stones.size();\n if (idx == n - 1)\n return true;\n if (idx >= n)\n return false;\n if (stones[idx + 1] - stones[idx] ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\n\n bool memo(vector<int>& stones, int index, int lastStep, vector<vector<int>>& dp) {\n if(index == stones.size() - 1) \n return true;\n\n if(dp[index][lastStep] != -1) return dp[index][lastStep];\n\n for(int i = index + 1; i < stones.size(); i++) {\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\n\n bool memo(vector<int>& stones, int index, int lastStep, vector<vector<int>>& dp) {\n if(index == stones.size() - 1) \n return true;\n\n if(dp[index][lastStep] != -1) return dp[index][lastStep];\n\n for(int i = index + 1; i < stones.size(); i++) {\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\nprivate:\n bool helper(int ind,int k,vector<int>&stones,vector<vector<int>> &dp){\n if(ind==(stones.size()-1))\n return true;\n \n if(dp[ind][k]!=-1)\n return dp[ind][k];\n bool canReach = false;\n \n for(int i=ind+1;i<sto... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool func(int i,vector<int> &stones,int k,vector<vector<int>> &dp)\n {\n if(i>=stones.size() || k==0)\n {\n return false;\n }\n if(i==stones.size()-1)\n {\n return true;\n }\n if(dp[i][k]!=-1)\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool func(int i,vector<int> &stones,int k,vector<vector<int>> &dp)\n {\n if(i>=stones.size() || k==0)\n {\n return false;\n }\n if(i==stones.size()-1)\n {\n return true;\n }\n if(dp[i][k]!=-1)\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool solve(vector<int> &stones, int index, int lastJump, int n, vector<vector<int>> &dp) {\n if (index == n - 1) // If we reach the last stone, return true\n return true;\n\n // If this state has already been computed, return the stored result\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n int check(int num, int i, vector<int>&stones){\n for(int j = i; j < stones.size(); j++){\n if(num == stones[j]) return j;\n }\n return -1;\n }\n bool solve(int i, int k, vector<int>&stones, vector<vector<int>>&dp){\n int n = stones... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool solve(vector<int>& stones,int lasti,int curri,vector<vector<int>>&dp){\n if(curri==stones.size()-1)\n return true;\n if(dp[lasti][curri]) return false;\n int lastjump=stones[curri]-stones[lasti];\n int nexti=curri+1;\n while(next... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool func(vector<int>& stones, int index, int jump, int &n, vector<vector<int>> &dp) {\n if(index == n - 1){\n return true;\n }\n if(dp[index][jump] != -1){\n return dp[index][jump];\n }\n bool flag = false;\n fo... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool helper(const vector<int>& stones, const int pos, const int lastjump, std::unordered_map<int, vector<short>>& cache) const {\n if(lastjump == 0) {\n return false;\n }\n else if(cache.count(pos) != 0 && cache.find(pos)->second[lastjump] != -... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\n\n bool solve(int k, vector<int> &stones, int idx, vector<vector<int>> &dp)\n {\n if(idx>stones.size())\n {\n return false;\n }\n if(idx==stones.size()-1)\n {\n return true;\n }\n if(dp[k][idx]!=-1) return dp[k]... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool helper(vector<int>& stones, int index, int lastJump, vector<vector<int>>& dp) {\n if (index == stones.size() - 1) return true;\n if (dp[index][lastJump] != -1) return dp[index][lastJump];\n\n for (int jump = lastJump - 1; jump <= lastJump + 1; ++jump... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool solve(vector<int>& stones,int n,int i,int p,vector<vector<int>> &dp){\n if(i==n-1)\n return true;\n if(i>=n)\n return false;\n if(dp[i][p]!=-1)\n return dp[i][p];\n int k=stones[i]-stones[p];\n bool ans=false;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool func(int i, int jumps, vector<int>& stones, vector<vector<int>>& dp){\n if(i==stones.size()-1)\n return 1;\n if(i>=stones.size())\n return 0;\n if(dp[i][jumps] != -1)\n return dp[i][jumps];\n bool ans=0;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n\n // int solve(vector<int>& s, unordered_map<int,int>&m, int i, int j, vector<vector<int>>&dp){\n // if(i>=s.size()-1) return 1;\n // if(dp[i][j]!=-1) return dp[i][j];\n // int ans = 0;\n // if(m.count(s[i]+j-1) && j!=1) ans = ans | solve(s,m,m[s[i... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n\n bool canCross(vector<int>& s) {\n int n = s.size();\n if(n==1) return 1;\n if(s[1]-s[0]>1) return 0;\n vector<vector<int>>dp(s.size()+1, vector<int>(s.size()+1,0));\n for(int i=1; i<=n; i++) dp[n-1][i]=1;\n unordered_map<int,int>m;\... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n unordered_map<int,int> M;\n bool hhh(vector<int> &stones,int jump,int i,vector<vector<int>> &dp){\n if(i==stones.size()-1)\n return true;\n bool a=false,b=false,c=false;\n if(jump==0)\n return 0;\n if(dp[i][jump]!=-1)\n retu... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n\nint solve(vector<int>&v,int n,int i,int last,unordered_map<int,int>&mp,vector<vector<int>>&dp){\n if(i==n-1)\n return true;\n if(i>n-1)\n return false;\n\n if(dp[i][last]!=-1)\n return dp[i][last];\n\n int a=0,b=0,c=0;\n\n if(mp[v[i]+last]){\n a=a... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "bool canreach(vector<int>& stones, long long int k, long long int i, long long int n, map<long long int, long long int>& mpp, vector<vector<int>> &dp){\n if(i == n-1) return true;\n\n if(dp[i][k] != -1) return dp[i][k];\n\n bool first = false;\n if(k-1 > 0 && mpp[stones[i] + k - 1] > 0){\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n int n = stones.size();\n vector<vector<int>> dp(n, vector<int>(n + 2, 0));\n dp[0][1] = 1;\n for(int i = 1; i < n; i++) {\n for(int j = 0; j < i; j++) {\n int dist = stones[i] - stone... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n int n = stones.size();\n vector<vector<int>> dp(n, vector<int>(n, 0));\n dp[0][1] = 1;\n for(int i = 1; i < n; i++) {\n for(int j = 0; j < i; j++) {\n int dist = stones[i] - stones[j]... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n int n = stones.size();\n vector<vector<int>> dp(n, vector<int>(n + 1, 0));\n dp[0][1] = 1;\n for(int i = 1; i < n; i++) {\n for(int j = 0; j < i; j++) {\n int dist = stones[i] - stone... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>>dp;\n bool solve(vector<int>&v, int idx, int step, int n){\n if(idx>n || step<0)\n return 0;\n if(idx==n-1){\n dp[idx][step]=1;\n return 1;\n }\n if(dp[idx][step]!=-1)\n return dp[id... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\nbool solve(int i,vector<int>&stones, vector<vector<int>>&dp,int k){\n int n = stones.size();\n if(i == n-1)return 1;\n if(dp[i][k]!=-1){\n return dp[i][k];\n }\n\n bool ans = 0;\n for(int jumps : {k-1,k,k+1}){\n if(jumps==0)continue;\n\n int... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool canCrossII(int sum, int prev, vector<int>& stones, map<int, int>& m,\n map<vector<int>, bool>& dp) {\n if (sum == stones[stones.size() - 1]) {\n return true;\n }\n if (m.count(sum) == 0) {\n return false;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool canCrossII(int sum, int prev, vector<int>& stones, map<int, int>& m,\n map<vector<int>, bool>& dp) {\n if (sum == stones[stones.size() - 1]) {\n return true;\n }\n if (m.count(sum) == 0) {\n return false;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n int n = stones.size();\n vector<vector<int>> jump(n, vector<int>(n + 1, 0));\n for (int i = 0; i < n; i ++) {\n for (int j = 0; j < i; j ++) {\n if (stones[i] - stones[j] >= n) continue;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n int n = stones.size();\n vector<vector<int>> jump(n, vector<int>(n + 1, 0));\n for (int i = 0; i < n; i ++) {\n for (int j = 0; j < i; j ++) {\n if (stones[i] - stones[j] >= n) continue;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool recurse(int i, int k, vector<int>& stones, vector<vector<int>>& dp){\n if(i == stones.size()-1){\n return true;\n }\n\n if(dp[i][k] != -1){\n return (bool) dp[i][k];\n }\n\n bool ret = false;\n vector<int> j... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n#define ll long long\n bool solve(vector<int>& stones, int index, int k, unordered_map<int, int>& mp, vector<vector<int>>& dp){\n if(index == stones.size()-1) return true;\n if(index >= stones.size()) return false;\n\n if(dp[index][k] != -1) return dp[inde... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n\n long long min(long long a, long long b){\n if(a<b) return a;\n return b;\n }\n bool will_cross(vector<int> &stones, int i, int k, vector<vector<int>> &dp){\n int dest=stones.back();\n int curr_place=stones[i];\n if(curr_place==dest) ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool find(int i, int lastSteps, vector<int>& stones, int n,\n vector<vector<int>>& dp) {\n if (i == n - 1)\n return true;\n\n if (dp[i][lastSteps] != -1)\n return dp[i][lastSteps];\n\n for (int j = i + 1; j < n; j++) {\n... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\nvector<vector<int>> dp;\nbool chk(int ind,int jl,vector<int> &stones){\n int n=stones.size();\n if(ind>=n-1)return true;\n if(dp[ind][jl]!=-1)return dp[ind][jl];\n int maxi=jl+1;\n int mini=jl-1;\n bool ans=false;\n //int dist=stones[ind+1]-stones[ind];\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n\nunordered_map<int,int> mp;\nbool func(int i, int last, vector<int> &stones,vector<vector<int>>&dp){\n int n =stones.size();\n if(i==n-1) return true;\n if(dp[i][last]!=-1) return dp[i][last];\n bool ans=false;\n for(int next= last-1;next<=last+1;next++){\... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n\n int target;\n vector<map<int,bool>> mp;\n bool rec(set<int> &s, int j, int cv){\n if(j == 0) return false;\n if(cv > target) return false;\n if(cv == target) return true;\n if(s.find(cv) == s.end()) return false;\n if(mp[j].find... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\nprivate:\n bool canJump(int idx, int jump, vector<int> &stones, map<int, int> &mp, vector<vector<int>> &dp) {\n if (idx == stones.size() - 1) return 1;\n if (dp[idx][jump] != -1) return dp[idx][jump];\n for(int i=-1; i<=1; i++) {\n int newStone = stones[... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\n int n;\n \npublic:\n bool solve(vector<int>& stones,int i,int k, vector<vector<int>>&dp){\n \n if(i>=n){\n return 0;\n }\n bool check=0;\n int j=i;\n int prev;\n if(i==0) prev=0;\n else prev=stones[i-1];\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool help(int i,int k,vector<int>&s,vector<vector<int>>&dp){\n if(i==s.size()-1){\n return true;\n }\n bool a=false;\n if(dp[i][k]!=-1)return dp[i][k];\n for(int j=i+1;j<s.size();j++){\n if(s[j]>(s[i]+k+1))break;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool help(int i,int k,vector<int>&s,vector<vector<int>>&dp){\n if(i==s.size()-1){\n return true;\n }\n bool a=false;\n if(dp[i][k]!=-1)return dp[i][k];\n for(int j=i+1;j<s.size();j++){\n if(s[j]>(s[i]+k+1))break;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool help(int i,int k,vector<int>&s,vector<vector<int>>&dp){\n if(i==s.size()-1){\n return true;\n }\n bool a=false;\n if(dp[i][k]!=-1)return dp[i][k];\n for(int j=i+1;j<s.size();j++){\n if(s[j]>(s[i]+k+1))break;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\nunordered_map<int,int>mp;\nbool su(int stone,int jump,int target,vector<vector<int>>&dp){\n \n if(stone==target){\n return true;\n }\n int f=mp[stone];\n if(dp[f][jump]!=-1){\n return dp[f][jump];\n }\n if(mp[stone]==0){\n return dp[f]... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\n int n;\n bool f(int ind, int jump, vector<int>& stone, vector<vector<int>>& dp){\n if(ind == n - 1) return true;\n if(dp[ind][jump] != -1) return dp[ind][jump];\n\n bool a = false;\n for(int j = ind + 1; j < n; j++){\n if(stone[j] > stone[ind]... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n vector<vector<int>> dp(2000,vector<int> (4001,0));\n for(int i=0;i<stones.size();i++){\n if(i==0){\n dp[i][0]=1;\n }\n else{\n for(int j=0;j<=i-1;j++){\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\n int n;\n bool f(int ind, int jump, vector<int>& stone, vector<vector<int>>& dp){\n if(ind == n - 1) return true;\n if(dp[ind][jump] != -1) return dp[ind][jump];\n\n bool a = false;\n for(int j = ind + 1; j < n; j++){\n if(stone[j] > stone[ind]... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\n int n;\n bool f(int ind, int jump, vector<int>& stone, vector<vector<int>>& dp){\n if(ind == n - 1) return true;\n if(dp[ind][jump] != -1) return dp[ind][jump];\n\n bool a = false;\n for(int j = ind + 1; j < n; j++){\n if(stone[j] > stone[ind]... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n vector < vector <int>> dp;\n bool recfun( vector<int>& a , int k , int i ){\n if( dp[ i ][k] !=-1) return dp[i][k];\n if( i == a.size()-1) return dp [i ][ k ] = true;\n int curr = a[i];\n bool flg ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\n \n vector<vector<int>>dp;\n bool fun(int ind,int jump,vector<int>&stones,int n){\n if(ind>=n)\n return false;\n if(ind==n-1)\n return true;\n if(dp[ind][jump]!=-1)\n return dp[ind][jump]==1;\n bool ans=false;\n if(ind==0)... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n\n unordered_map<int,int> isPresent, ind;\n\n bool f(vector<int> &stones, vector<vector<int>> &dp, int i, int lastJump){\n if(i == stones.size() - 1){\n return true;\n }\n\n if(dp[i][lastJump] != -1){\n return dp[i][lastJump];\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n\n int target;\n vector<map<int,bool>> mp;\n bool rec(set<int> &s, int j, int cv){\n if(j == 0) return false;\n if(cv > target) return false;\n if(cv == target) return true;\n if(s.find(cv) == s.end()) return false;\n if(mp[j].find... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n\n unordered_map<int,int>mp;\n\n bool solve(vector<int>&nums,int i,int k,vector<vector<int>>&dp){\n if(i>nums.size())return false;\n if(i==nums.size()-1)return true;\n if(mp[nums[i]+k]<=i)return false;\n if(dp[i][k]!=-1)return dp[i][k];\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n\n bool helper(int ind, int jumps, vector<int>& stones, vector<vector<int>>& dp){\n if(ind == stones.size()-1) return true;\n\n if(dp[ind][jumps] != -1) return dp[ind][jumps];\n\n bool ans = false;\n for(int i = ind+1; i<stones.size(); i++){\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n if(stones.size()==1)return true;\n if(stones[1]!=1)return false;\n vector<vector<int>> dp(stones.size(), vector<int>(2001, -1));\n return solve(1, 1, stones, dp);\n }\nprivate:\n bool solve(int i, int k,... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n int solve(int idx, vector<int>& stones, int jump, int &n, vector<vector<int>> &dp){\n if(idx==n-1) return true;\n if(dp[idx][jump]!=-1) return dp[idx][jump];\n int i = idx;\n bool a = false;\n while(i<n && (stones[idx]+jump+1)>=stones[i]){\n... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool canFrogCross(int index,int k,vector <int> &stones,vector <vector <int>>&dp) {\n int n = stones.size();\n // base case\n if(index == n-1)\n return true;\n if(dp[index][k] != -1)\n return dp[index][k];\n // main case... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n\n bool checkCross(int i,int jump,vector<int>& stones,vector<vector<int>>& dp) {\n if(i==stones.size()-1) return true;\n if(i>=stones.size()) return false;\n\n if(dp[i][jump]!=-1) return dp[i][jump]==1?true:false;\n\n bool ans = false;\n\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n\n\n bool helper (int pos, int k, map<int,int>mp,int target)\n {\n if(pos==target)\n {\n return 1;\n }\n if(pos > target || k <0 || mp.find(pos)==mp.end())\n {\n return 0;\n }\n bool h1,h2;\n if(k... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n/*\n int n;\n unordered_map<int, int> mp;\n int t[2001][2001];\n \n bool solve(vector<int>& stones, int curr_stone_index, int prevJump) {\n if(curr_stone_index == n-1)\n return true;\n \n bool result = false;\n \n if(t[... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool solve(int index, int k, vector<int>&stones, vector<vector<int>>&dp){\n if(index == stones.size() - 1)return true;\n if(dp[index][k]!=-1){return dp[index][k];}\n for(int i=k+1;i>=k-1;i--){\n for(int j=i;j>=1;j--){\n if(index ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n int bs(int l, int h, vector<int>&nums, int key){\n \n while(l<=h){\n \n int mid=(h-l)/2+l;\n if(nums[mid]==key){\n // cout<<\"yay\";\n // cout<<mid;\n return mid;\n }\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n#define dd double\n#define sz size()\n#define rtn return\n#define rnt rtn\n\n#define vi vector<int>\n#define vvi vector<vi>\n#define vvvi vector<vvi>\n#define vl vector<ll>\n#define vvl vector<vl>\n#define vd vector<dd>\n#define vvd vec... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n\n bool solve(int idx,int curr_jump,vector<int>& stones,vector<vector<int>>&dp)\n {\n\n if(idx==stones.size()-1)\n {\n return true;\n }\n\n\n if(dp[idx][curr_jump]!=-1)\n {\n if(dp[idx][curr_jump]==1)\n {\n... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\n\n bool memo(vector<int>& stones, int index, int lastStep, vector<vector<int>>& dp) {\n if(index == stones.size() - 1) \n return true;\n\n if(dp[index][lastStep] != -1) return dp[index][lastStep];\n\n for(int i = index + 1; i < stones.size(); i++) {\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool solveRec(int ind, int curr_jump, vector<int> &arr, map<int,int> &mp){\n if(curr_jump<=0) return false;\n\n if(ind==arr.size()-1) return true;\n\n if(!mp[arr[ind] + curr_jump]) return 0;\n\n bool op1 = solveRec(mp[arr[ind]+curr_jump]-1, curr_ju... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool solveRec(int ind, int curr_jump, vector<int> &arr, map<int,int> &mp){\n if(curr_jump<=0) return false;\n\n if(ind==arr.size()-1) return true;\n\n if(!mp[arr[ind] + curr_jump]) return 0;\n\n bool op1 = solveRec(mp[arr[ind]+curr_jump]-1, curr_ju... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\npublic:\n bool f(vector<int> &v,int idx,int k,int n,map<int,int> &mp,vector<vector<int>> &dp){\n if(idx==n-1) return true;\n if(dp[idx][k] != -1) return dp[idx][k];\n bool res1=false,res2=false,res3=false;\n if(mp.count(v[idx] + k-1) && k!=1) res1 = f(v,mp[v... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 3 | {
"code": "class Solution {\n unordered_map<int,int> mp;\n int solve(int i, int k, vector<int> &stones, vector<vector<int>> &dp){\n if(i==stones.size()-1)return 1;\n if(dp[i][k]!=-1)return dp[i][k];\n\n int ans=false;\n if(mp.count(stones[i]+k))ans=ans||solve(mp[stones[i]+k],k,stones... |
404 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of all left leaves.</em></p>
<p>A <strong>leaf</strong> is a node with no children. A <strong>left leaf</strong> is a leaf that is the left child of another node.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
404 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of all left leaves.</em></p>
<p>A <strong>leaf</strong> is a node with no children. A <strong>left leaf</strong> is a leaf that is the left child of another node.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
404 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of all left leaves.</em></p>
<p>A <strong>leaf</strong> is a node with no children. A <strong>left leaf</strong> is a leaf that is the left child of another node.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
404 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of all left leaves.</em></p>
<p>A <strong>leaf</strong> is a node with no children. A <strong>left leaf</strong> is a leaf that is the left child of another node.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
404 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of all left leaves.</em></p>
<p>A <strong>leaf</strong> is a node with no children. A <strong>left leaf</strong> is a leaf that is the left child of another node.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
404 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of all left leaves.</em></p>
<p>A <strong>leaf</strong> is a node with no children. A <strong>left leaf</strong> is a leaf that is the left child of another node.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
404 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of all left leaves.</em></p>
<p>A <strong>leaf</strong> is a node with no children. A <strong>left leaf</strong> is a leaf that is the left child of another node.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
404 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of all left leaves.</em></p>
<p>A <strong>leaf</strong> is a node with no children. A <strong>left leaf</strong> is a leaf that is the left child of another node.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
404 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of all left leaves.</em></p>
<p>A <strong>leaf</strong> is a node with no children. A <strong>left leaf</strong> is a leaf that is the left child of another node.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
404 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of all left leaves.</em></p>
<p>A <strong>leaf</strong> is a node with no children. A <strong>left leaf</strong> is a leaf that is the left child of another node.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
404 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of all left leaves.</em></p>
<p>A <strong>leaf</strong> is a node with no children. A <strong>left leaf</strong> is a leaf that is the left child of another node.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
404 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of all left leaves.</em></p>
<p>A <strong>leaf</strong> is a node with no children. A <strong>left leaf</strong> is a leaf that is the left child of another node.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
406 | <p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code... | 0 | {
"code": "#include <algorithm>\n#include <list>\n#include <vector>\nusing namespace std;\n\nclass Solution {\n public:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sort(people.begin(), people.end(), [&](const auto& p1, const auto& p2) {\n return h_val(p1) * 2000 + k_... |
406 | <p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n std::vector<std::vector<int>> ans(people.size());\n std::vector<std::pair<int16_t, int16_t>> lst(people.size(), std::pair{-1, 1});\n\n std::sort(people.begin(), people.end());\n\n ... |
406 | <p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sort(people.begin(), people.end(), [](auto& a, auto& b) {\n if (a[0] != b[0]) {\n return a[0] < b[0];\n }\n return a[1] > b[1];\n });\n v... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.