id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
0
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int> &arr, int difference) {\n int n = arr.size();\n vector<int> dp(n, 1);\n vector<int> numbers(20001, 0);\n int max = 1;\n for (int i = 0; i < n; i++) {\n int num = arr[i];\n int prev = n...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
0
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n unordered_map<int,int>mp;\n int ans=1;\n for(auto &it : arr)\n {\n int el=it-difference;\n if(mp.find(el)!=mp.end())\n {\n mp[it]=mp[el]+1;...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
0
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr,int difference) {\n\n unordered_map<int,int> dp;\n int ans = 0;\n\n for(int i=0; i<arr.size(); i++) {\n \n int temp = arr[i] - difference;\n int tempAns = 0;\n \n ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
0
{ "code": "// class Solution {\n// public:\n// int f (int j ,int i , int d ,vector<int>& arr,vector<vector<int>> &dp){\n// int n = arr.size();\n// if (i>=n) {\n// return 0;\n// }\n// if (dp[j+1][i]!=-1) return dp[j+1][i];\n// int nottake = f(j,i+1,d,arr,dp);\n//...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
0
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n = arr.size();\n unordered_map<int,int> mp;\n int ans = 1;\n for(int i = 0;i<n;i++){\n int cnt = 0;\n if(mp.find(arr[i]-difference)!=mp.end()){\n ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
0
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n unordered_map<int, int> dp;\n int len = 0;\n\n for (int i = 0; i < arr.size(); i++) {\n int before = 0;\n if (dp.find(arr[i] - difference) != dp.end()) \n be...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
0
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int ans=0;\n unordered_map<int,int> dp;\n\n for(int i=0;i<arr.size();i++)\n {\n int temp=arr[i]-difference;\n int tempans=0;\n\n //find temp in dp\n ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
0
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int diff) {\n if(arr.size()<=1){\n return arr.size();\n }\n unordered_map<int,int> dp;\n int ans=0;\n for(int i=0;i<arr.size();i++){\n int nextele = arr[i]-diff;\n int...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
1
{ "code": "class Solution {\npublic:\n \n int longestSubsequence(vector<int>& arr, int difference) {\n \n unordered_map<int,int>dp;\n int answer = 1;\n \n for (int a : arr) {\n int beforeA = dp.count(a - difference) ? dp[a - difference] : 0;\n dp[a] = befo...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
2
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n = arr.size();\n vector<int> dp(4e4+5);\n int maxi = 0;\n for(int i=0;i<n;i++){\n dp[arr[i]+2e4]=1+dp[arr[i]-difference+2e4];\n maxi = max(maxi, dp[arr[i]+2e4])...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
2
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n unordered_map<int, int> myMap;\n int ans=1, dp[arr.size()];\n for(int i=0;i<arr.size();i++){\n auto it = myMap.find(arr[i]-difference);\n if(it == myMap.end()){\n ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
2
{ "code": "// #define int long long\nclass Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int maxi = -1e9;\n// unordered_map<int, int> m;\n\nvector<int> dp(40001,0);\n for (int i = 0; i < arr.size(); i++)\n {\n arr[i]+=2*1e4;\n dp[arr[i]]=max(dp[arr[i]],dp[arr[...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
2
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& nums, int difference) {\n int n = nums.size();\n vector<int> V(40001,0); // 10k -> 20K , -10k -> 0, 0 -> 10k , x -> 10k + x\n int res = 1;\n V[nums[0] + 20000] = 1;\n for(int i=1;i<n;i++)\n {\n ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
2
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n vector<int> dp(42222, 0);\n int ans = 0;\n for(int i=0;i<arr.size();i++) {\n int rn = arr[i] + 20000;\n dp[rn] = dp[rn-difference] + 1;\n ans = max(dp[rn], ans);...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
2
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n map<int,int> dp;\n //value, max_length\n\n int maxAns = 0;\n for (int i = 0 ; i<arr.size(); ++i){\n if (dp.count(arr[i] - difference))\n dp[arr[i]] = dp[arr[i] -...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
2
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n map<int, int> longestSubsequenceMap;\n\n int n = arr.size();\n\n if (n==0) {\n return 0;\n }\n int longestSubsequenceLength = 1;\n\n longestSubsequenceMap.insert(...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
2
{ "code": "class Solution {\npublic:\n int call(vector<int>& arr,int k,int i,int j,vector<vector<int>>& dp)\n {\n if(i>=arr.size())\n {\n return 0;\n }\n if(dp[i][j+1]!=-1)\n return dp[i][j+1];\n int l=call(arr,k,i+1,j,dp);\n if(j==-1 || arr[i]-arr[j]=...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
2
{ "code": "class Solution {\npublic:\n int solve(int i,int p,vector<int>& arr, int d ){\n if(i==arr.size()) return 0;\n int t=0;\n if(p==-1||arr[i]-arr[p]==d){\n t=1+solve(i+1,i,arr,d);\n }\n int m=solve(i+1,p,arr,d);\n return max(m,t);\n }\n int longestSub...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
2
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n map<int, int> m;\n int maxi = 1;\n for(auto num: arr) {\n int prev = num - difference;\n if(m.find(prev) == m.end()) {\n m[num] = 1;\n } else {\n ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
2
{ "code": "class Solution {\npublic:\n int f(int idx,int p_idx,int d,vector<int>& ar,vector<vector<int>>& dp){\n if(idx==ar.size()) return 0;\n if(dp[idx][p_idx+1] != -1) return dp[idx][p_idx+1];\n int nt = f(idx+1,p_idx,d,ar,dp);\n int t = -1;\n if(p_idx == -1 || ar[idx]-ar[p_id...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
2
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n unordered_map<int,int> table;\n int ans=1;\n for(int i=0;i<arr.size();i++)ans= max(ans,table[arr[i]]=table[arr[i]-difference]+1);\n return ans;\n }\n};", "memory": "60400" }
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
2
{ "code": "class Solution {\npublic:\n\n int trav(vector<int>& arr, int diff,int i,int n,int pre,vector<vector<int>> &dp)\n {\n if(i==n)\n {\n return 0;\n\n }\n else if(dp[i][pre+1]!=-1)\n {\n return dp[i][pre+1];\n }\n\n int ans1=0;\n ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int diff) {\n int n = size(arr), ans = 0;\n unordered_map<int, int> prevIdx;\n\n vector<int> dp(n);\n for(int i = 0; i < n; i++){\n int prevNum = arr[i] - diff;\n\n if(prevIdx.count(pre...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n=arr.size();\n int maxLength=1;\n /*vector<unordered_map<int, int>> dp(n);\n for(int j=1; j<n; j++) {\n for(int i=0; i<j; i++) {\n if(dp[i].count(difference...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n=arr.size();\n int maxLength=1;\n /*vector<unordered_map<int, int>> dp(n);\n for(int j=1; j<n; j++) {\n for(int i=0; i<j; i++) {\n if(dp[i].count(difference...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n = arr.size();\n // if(n<=1) return n;\n\n int ans =1;\n //to store the length of the longest subsequence ending at each element\n unordered_map<int,int> dp(n+1);\n for...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int d) {\n int n=arr.size();\n vector<int>dp(5e4+10,0);\n dp[arr[0]+3e4]++;\n for(int i=1;i<n;i++){\n dp[arr[i]+3e4]=max(dp[arr[i]+3e4-d]+1,dp[arr[i]+3e4]);\n }\n int ans=0;\n for(in...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n = arr.size();\n int d = difference;\n map<int, int> dp;\n for(int i = 0; i < n; ++i)\n {\n dp[arr[i]] = dp[arr[i] - d] + 1;\n }\n int high = -1;\n ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int ans = 0;\n map<int, int> dp;\n for(auto x: arr) {\n dp[x] = max(dp[x], 1 + dp[x - difference]);\n ans = max(ans, dp[x]);\n }\n return ans;\n }\n};", ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n\n int longestSubsequence(vector<int>& arr, int difference) {\n map<int,int> dp; \n int maxi=0;\n int n=arr.size();\n for(int i=0;i<n;i++){\n dp[arr[i]]=dp[arr[i]-difference]+1;\n maxi=max(maxi,dp[arr[i]]);\n }\n return maxi;\n ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n map<int,int> mp;\n int ans = 0;\n mp[0] = 0;\n map<int,int> mp2;\n int ans2 = 0;\n mp2[0] = 0;\n for(int i = 0; i < arr.size(); i++){\n int r = 1 + mp2[arr...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n=arr.size();\n map<int,int> mp;\n int ans=-1;\n for(int i=0;i<n;i++){\n cout<<mp[arr[i]-difference]<< \" sdf \";\n int p=(mp.find(arr[i]-difference)!=mp.end()?m...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n = arr.size();\n unordered_map<int, int> cache; cache.reserve(n);\n int ret = 0;\n for (int i = 0; i < n; ++i) {\n cache[arr[i]] = max(cache[arr[i]], 1 + cache[arr[i] - di...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n = arr.size(), ans = 1;\n vector<int> temp(n, 1);\n map<int, int> m;\n\n for(int i=0;i<n;i++)\n {\n if(m.find(arr[i]-difference) != m.end())\n {\n ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n = arr.size();\n int dp[n+5];\n memset(dp,0,sizeof(dp));\n map<int,int> mp;\n int mx = -1;\n dp[0]=1; mp[arr[0]]=1;\n for(int i=1; i<n; i++){\n dp[i] ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int n, D;\n int t[100010];\n int longestSubsequence(vector<int>& arr, int d) {\n // n = arr.size();\n // D = d;\n // memset(t, -1, sizeof t);\n // int res = 0;\n // for(int i = 0; i < n; i++){\n // res = max(res, 1 + solve(i...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int getLongestSeq(vector<int>& arr, int& diff, int i, int prev, vector<vector<int>>& dp){\n if(i >= arr.size()) return 0;\n\n if(dp[i][prev+1] != -1) return dp[i][prev+1];\n \n int pick = 0;\n int noPick = getLongestSeq(arr, diff, i+1 , prev...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& nums, int difference) {\n int n = nums.size();\n vector<int> dp(n,1); // LIS ending at i\n int res =1;\n map<int,int> M;\n M[nums[0]]=1;\n for(int i=1;i<n;i++)\n {\n if(M.find(nums...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n vector<int> dp(arr.size(), 1);\n map<int, int> index;\n int ret = 0;\n for(int i=0;i<arr.size();i++){\n int before = arr[i] - difference;\n if(index.count(before)){\...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int dif) {\n int n = arr.size();\n vector<int>dp(n,1);\n int maxi = 1;\n map<int,int>mp;\n mp[arr[0]] = 0;\n for(int i = 1;i<n;i++){\n \n if(mp.find(arr[i]-dif)!=mp.en...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n Solution(){\n ios_base :: sync_with_stdio( false );\n cin.tie( nullptr ) , cout.tie( nullptr );\n }\n int longestSubsequence(vector<int>& arr, int diff) {\n int len = arr.size() , ans = 0;\n vector< int >res( len , 0 );\n unordered_map...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& nums, int diff) {\n int ans = 1;\n int n = nums.size();\n vector<int> dp(n, 1);\n unordered_map<int, int> map;\n dp[0] = 1;\n map[nums[0]] = 1;\n for (int i = 1; i < n; i++) {\n in...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n=arr.size();\n vector<int> dp(n,0),cp(n,1);\n unordered_map<int,int> mp;\n dp[0]=1;\n mp[arr[0]]=0;\n for(int i=1;i<n;i++){\n dp[i]=dp[i-1];\n if(...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n vector <int> dp(arr.size(),1);\n int ans=1;\n map <int,int> m;\n for(int i=0;i<arr.size();i++){\n int tmp=1;\n tmp=max(tmp,1+m[arr[i]-difference]);\n m[ar...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n map<int ,int>m;\n vector<int> dp(arr.size() ,1);\n int res = 1;\n for(int i = 0 ; i < arr.size() ; i++){\n if(m[arr[i]-difference]) dp[i] = dp[m[arr[i]-difference]-1] +1;\n ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int diff) {\n \n int n=arr.size();\n vector<int>dp(n,1);\n\n for(int i=1;i<n;i++)\n {\n // for(int j=i-1;j>=0;j--)\n // {\n // if(arr[i]-arr[j]==diff) {dp[i]=1+dp[j];\n // break;...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n = arr.size();\n vector<int> dp(n, 1);\n int ans = 1;\n\n unordered_map<int, int> hash;\n hash.emplace(arr[0], 0);\n\n for (int i = 1; i < n; ++i) {\n int v...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int n = arr.size();\n\n vector<pair<int, int>> V;\n for(int i=0;i<n;i++) {\n V.push_back({arr[i], i});\n }\n sort(V.begin(), V.end());\n\n vector<int> DP(n, 1);\n...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n unordered_map<int, unsigned int> dp;\n unsigned int max = 1;\n for (int x : arr) {\n if (dp.find(x - difference) != dp.end()) {\n if (dp[x - difference] + 1> max) {\n ...
1,330
<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p> <p>A <strong>subsequence</strong>...
3
{ "code": "class Solution {\npublic:\n int longestSubsequence(vector<int>& arr, int difference) {\n int maxLen = 1;\n unordered_map<int, int> dp;\n unordered_set<int> ele;\n ele.insert(arr[0]);\n dp[arr[0]] = 0;\n\n for(int ind = 1; ind<arr.size(); ind++){\n if(...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
0
{ "code": "class Solution {\nprivate:\n int dx[4] = {0,0,1,-1};\n int dy[4] = {1,-1,0,0};\npublic:\n bool isPossible(int x, int y, vector<vector<int>> &grid)\n {\n int n = grid.size();\n int m = grid[0].size();\n if( x >= 0 && x <n && y >=0 && y < m)\n return 1;\n re...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
0
{ "code": "class Solution {\npublic:\n const vector<tuple<int, int>> dxy = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n\n int get_max(vector<vector<int>>& grid, const int i, const int j)\n {\n if (grid[i][j] <= 0)\n {\n return 0;\n }\n\n // ! matrix如果只有一个元素的话根本就不会触发for loop,\n...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
0
{ "code": "class Solution {\npublic:\n int rec(vector<vector<int>>& grid, int x, int y){\n int n = size(grid), m = size(grid[0]);\n \n if(x < 0 or x >= n or y < 0 or y >= m or grid[x][y] == 0)\n return 0;\n\n int gold = grid[x][y];\n grid[x][y] = 0;\n\n int maxG...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
0
{ "code": "class Solution {\npublic:\nint R, C;\nint gold = 0;\nint dirs[5] = {1,0,-1,0,1};\n void collect(vector<vector<int>>& grid, int row, int col, int start){\n start += grid[row][col];\n gold = max(gold, start);\n int tmp = grid[row][col];\n grid[row][col] = 0;\n\n for (int...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
0
{ "code": "#pragma GCC optimize(\"Ofast\")\nstatic auto _ = [](){std::ios::sync_with_stdio(false); std::cin.tie(nullptr); return nullptr;}();\n\nclass Solution {\n int dx[4] = {-1, 1, 0, 0};\n int dy[4] = {0, 0, -1, 1};\n int dfs(int i, int j, int row, int col, std::vector<std::vector<int>> &grid) {\n ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
0
{ "code": "class Solution {\npublic:\n \n int dir[5] = {1,0,-1,0,1};\n \n int dfs(vector<vector<int>> &grid, int x, int y) {\n int n = grid.size();\n int m = grid[0].size();\n \n \n if (x < 0 || x >= n or y < 0 || y >= m || !grid[x][y]) {\n return 0;\n ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
1
{ "code": "class Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n int maxGold = 0;\n for (int r = 0; r < m; r++)\n for (int c = 0; c < n; c++)\n maxGold = max(maxGold, findMaxGold(grid, m, n, r, c));\n...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
1
{ "code": "class Solution {\npublic:\n int ans = 0;\n void dfs(vector<vector<int>>& grid, int i, int j, int sum) {\n if (i < 0 || j < 0 || i >= grid.size() || \n j >= grid[0].size() || grid[i][j] == 0) {\n return;\n }\n int temp = grid[i][j];\n grid[i][j] = 0;\n...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
1
{ "code": "class Solution {\npublic:\n int m, n;\n vector<vector<int>> directions{{-1, 0}, {1, 0}, {0, 1}, {0, -1}};\n int DFS(vector<vector<int>>& grid, int i, int j) {\n\n if(i >= m || i < 0 || j >= n || j < 0 || grid[i][j] == 0) {\n return 0; //Zero gold\n }\n\n int origina...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
1
{ "code": "class Solution {\npublic:\n int m,n;\n vector<vector<int>> directions{{0,-1},{0,1},{-1,0},{1,0}};\n int dfs(vector<vector<int>>& grid,int x,int y)\n {\n if(x>=m|| x<0 || y>=n ||y<0 || grid[x][y]==0)\n {\n return 0;\n }\n int originalvalue=grid[x][y];\n ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
2
{ "code": "class Solution {\npublic:\n int n,m;\n int ans;\n vector<vector<int>>dir={{1,0},{0,1},{-1,0},{0,-1}};\n void solve(int i, int j,int gold,vector<vector<int>>&visited,vector<vector<int>>& grid){\n if(i<0 || j<0 || i>=n || j>=m || visited[i][j] || grid[i][j]==0){\n return;\n ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
2
{ "code": "/**\n * @file 1219.cpp\n * @brief This file contains the implementation of a solution for a problem related to finding the maximum gold in a grid.\n * @details The grid is represented as a 2D vector. Each cell in the grid represents a gold mine with a certain amount of gold.\n * The goal is to find the max...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
2
{ "code": "class Solution\n{\npublic:\n int getMaximumGold(vector<vector<int>> &grid)\n {\n int maxi = 0;\n for (int i = 0; i < grid.size(); i++)\n {\n for (int j = 0; j < grid[i].size(); j++)\n {\n if (grid[i][j] != 0)\n {\n ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
2
{ "code": "class Solution {\npublic:\n int f(int i,int j,vector<vector<int>>&arr){\n int n=arr.size();int m=arr[0].size();\n if(i>=n || i<0 || j>=m || j<0 || arr[i][j]==-1 || arr[i][j]==0)return 0;\n int s=0;int maxi=0;\n int k=arr[i][j];\n arr[i][j]=-1;\n int l=k+f(i,j+1,...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
2
{ "code": "class Solution {\npublic:\n\n vector<vector<int>> dirs = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};\n void bt(vector<vector<int>>& grid, int m, int n, int i, int j, int& maxsofar, int sum, vector<vector<int>>& vis)\n {\n if(i < 0 || i >= m || j < 0 || j >= n || vis[i][j] == 1 || grid[i][j] == 0)\n...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
2
{ "code": "class Solution {\npublic:\n\n int solver(vector<vector<int>> &vis,vector<vector<int>>& grid,int n,int m,int i,int j){\n \n if(i<0 || i>=n || j<0 || j>=m || grid[i][j]==0 || vis[i][j] == 1){\n\n return 0;\n }\n \n vis[i][j] = 1;\n\n int l = grid[i][j] ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
2
{ "code": "#include <vector>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n int maxGold = 0;\n\n // DFS function to explore all possible paths\n functi...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
2
{ "code": "class Solution {\npublic:\n \n int dfs(int r,int c,vector<vector<int>>&grid,vector<vector<bool>>&vis)\n\t{\n\t\tif(r>=grid.size() || c>=grid[0].size() || r<0 || c < 0 || vis[r][c]== true || grid[r][c] ==0)\n\t\treturn 0;\n\t\t\n\t\tint sum=grid[r][c];\n\t\tvis[r][c]=true;\n\n\t\tint dir[4][2]={{1,0},...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
2
{ "code": "class Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n int maxGold = 0;\n // Define the four possible directions (up, down, left, right)\n vector<pair<int, int>> directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n \n // Function to perform DFS to ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
2
{ "code": "class Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n int maxGold = 0;\n \n function<void(int,int,int)> dfsBacktrack = [&](int i, int j, int currentGold) {\n if (i < 0 || i >= m || j < ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n function<int(int, int)> dfs = [&](int i, int j) {\n if (i < 0 || i >= m || j < 0 || j >= n || !grid[i][j]) {\n return 0;\n }\n ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n int maxGold = 0;\n \n function<void(int,int,int)> dfsBacktrack = [&](int i, int j, int currentGold) {\n if (i < 0 || i >= m || j < ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n \n \n \n \n int solve(int i,int j,int n,int m,vector<vector<int>>& vis,vector<vector<int>>& mat){\n if (i < 0 || i >= n || j < 0 || j >= m || vis[i][j] || mat[i][j] == 0) {\n return 0;\n }\n int gold=mat[i][j];\n\n vis[i][j]=1;\n i...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\nprivate:\n int btHelper(const vector<vector<int>>& grid, vector<vector<bool>>& visited, int m, int n, int i, int j, int val) {\n int maxGold(val);\n if (i > 0 && grid[i-1][j] > 0 && !visited[i-1][j]) {\n visited[i-1][j] = true;\n maxGold = max(maxGol...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\nprivate: \n vector<vector<int>> dir{\n {0, 1},\n {1, 0},\n {0, -1},\n {-1, 0}\n };\npublic:\n int getMaximumGold(vector<vector<int>>& grid) \n {\n int ans = 0, cur = 0;\n vector<vector<bool>> visited(grid.size(), vector<bool>(grid[0].s...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n void solve(vector<vector<int>>& grid,int n,int m,int x,int y,int &gold,int &maxi,vector<vector<int>>& vis){\n gold+=grid[x][y];\n vis[x][y]=1;\n maxi=max(maxi,gold);\n int row[]={x-1,x,x+1,x};\n int col[]={y,y+1,y,y-1};\n\n for(int i=...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n\n const vector<int> diri = {1, -1, 0, 0};\n const vector<int> dirj = {0, 0, -1, 1};\n\n bool validCell(int row, int col, vector<vector<int> >& grid, vector<vector<bool> >& vis) {\n return row >= 0 && row < grid.size() && col >= 0 && col < grid[0].size() && grid[r...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n int ans = 0;\n int m = grid.size(), n = grid[0].size();\n\n for (int i = 0; i < m; ++i) {\n for (int j = 0; j < n; ++j) {\n if (grid[i][j] > 0) {\n vector<vecto...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\n vector<int>delrow = {0 , 0 , 1 , -1};\n vector<int>delcol = {1 , -1 , 0 , 0};\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n int res = 0;\n vector<vector<bool>> vis(m , vector<bool>(n , fa...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\nbool isValid(int i, int j, int n,int m, vector<vector<int>>&v,vector<vector<int>> &vis){\n if(i<0||j<0||i>=n||j>=m||vis[i][j]==1||v[i][j]==0) return false;\n return true;\n}\nint sol(int i,int j, vector<vector<int>>&v,vector<vector<int>>&vis){\n int n=v.size();\n int ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "#include <vector>\n#include <algorithm>\n\nusing namespace std;\n\nint solve(vector<vector<int>>& grid, int i, int j, vector<vector<bool>>& vis) {\n int n = grid.size();\n int m = grid[0].size();\n\n if (i < 0 || i >= n || j < 0 || j >= m || grid[i][j] == 0 || vis[i][j]) {\n return 0;\n ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n int ans = 0;\n int m = grid.size(), n = grid[0].size();\n\n for (int i = 0; i < m; ++i) {\n for (int j...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "\nclass Solution {\npublic:\n\n bool isValid(int i, int j, vector<vector<int>> &g, vector<vector<bool>> &v)\n {\n int m = g.size();\n int n = g[0].size();\n\n return (i >= 0 && i<m && j>=0 && j<n && g[i][j] >0 && !v[i][j]);\n }\n\n void DFS(int i, int j, vector<vector<int>>...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "\nclass Solution {\npublic:\n\n bool isValid(int i, int j, vector<vector<int>> &g, vector<vector<bool>> &v)\n {\n int m = g.size();\n int n = g[0].size();\n\n return (i >= 0 && i<m && j>=0 && j<n && g[i][j] >0 && !v[i][j]);\n }\n\n void DFS(int i, int j, vector<vector<int>>...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n // Main function to find the maximum amount of gold\n int getMaximumGold(vector<vector<int>>& grid) {\n int maxNum = 0;\n int rows = grid.size();\n int cols = grid[0].size();\n \n // Loop through every cell in the grid\n for (int i...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n // Main function to find the maximum amount of gold\n int getMaximumGold(vector<vector<int>>& grid) {\n int maxNum = 0;\n int rows = grid.size();\n int cols = grid[0].size();\n \n // Loop through every cell in the grid\n for (int i...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n int dfs(vector<vector<int>>& grid,vector<vector<bool>>& visited,int i,int j){\n int m=grid.size(),n=grid[0].size();\n if(i>=m||j>=n||i<0||j<0||visited[i][j]||grid[i][j]==0) return 0;\n visited[i][j]=true;\n int ans=grid[i][j];\n ans+=max({d...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\nint n;\nint m;\nbool isValid(int x,int y){\n if(x<0 || y<0 || x>=n || y>=m)\n return false;\n return true;\n}\nint find(int u,int v, vector<vector<int>>& grid , vector<vector<bool>>&vis,int &count ,int &ans){\n if(grid[u][v]==0 || vis[u][v]==true)\n return 0;\n\n ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n int dx[4] = {-1,0,0,1};\n int dy[4] = {0,-1,1,0};\n void f(vector<vector<int>> &grid,int srcRow,int srcCol,int currGold,int &maxGold,vector<vector<bool>> &visited)\n {\n visited[srcRow][srcCol]=1;\n currGold+=grid[srcRow][srcCol];\n maxGold = max...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n int findmax(int val1, int val2)\n {\n return val1>val2?val1:val2;\n }\n int getMaximumGold(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n int max = 0;\n for (int i = 0 ;i<m;i++){\n for(int...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\nint m;\nint n;\n int solve(vector<vector<int>>& data, vector<vector<bool>>& visited, int x, int y) {\n if (x < 0 || y < 0 || x == m || y == n)\n return 0;\n if (data[x][y] == 0 || visited[x][y])\n return 0;\n visited[x][y] = true;\n\n...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n int res = 0;\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n vector<vector<bool>> visited(m, vector<bool>(n));\n ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n int f(int i, int j, vector<vector<int>>& A, vector<vector<bool>>& visited){\n size_t n = A.size();\n size_t m = A[0].size();\n\n if(A[i][j] == 0) return 0;\n if(visited[i][j]) return 0;\n\n visited[i][j] = true;\n\n int left = A[i][j]...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n int dfs(int row, int col, vector<vector<int>>& grid, vector<vector<bool>>& visited) {\n if (row < 0 || col < 0 || row >= grid.size() || col >= grid[0].size() || visited[row][col] || grid[row][col] == 0) {\n return 0;\n }\n\n visited[row][col] =...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n map<pair<int,int>,int>vis;\n int func( int r , int c , int n , int m , vector<vector<int>>& grid )\n {\n vis[make_pair(r,c)]=1;\n if(r>=n || c>=m || r<0 || c<0 || grid[r][c]==0 )\n {\n return 0;\n }\n\n int u=0,d=0,rt=0,l=0; \...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n vector<int> sums = {0};\n for(int i = 0; i < grid.size(); i++) {\n for(int j = 0; j < grid[0].size(); j++) {\n if(grid[i][j] > 0) {\n doit(sums, grid, i, j, 0);\n ...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& grid, vector<vector<bool>>& visited, int i, int j, int& maxGold, int curGold) {\n\n maxGold = max(maxGold, curGold);\n visited[i][j] = true;\n int goldVal = grid[i][j];\n grid[i][j] = -1;\n int n = grid.size();\...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "class Solution {\npublic:\n\n bool isValid(int row,int col,vector<vector<int>>&vis,vector<vector<int>>&grid,int n, int m){\n if(row>=0&&col>=0&&row<n&&col<m&&vis[row][col]==0&&grid[row][col]!=0) return true;\n return false;\n }\n\n void getGold(int row,int col,int sum,vector<vector<i...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "using pt = pair<int, int>;\n\nstruct State {\n int mask;\n short pos;\n short w;\n};\n\nconst int dx[] = {-1, 0, 0, 1};\nconst int dy[] = {0, -1, 1, 0};\n\nclass Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n vector<pt> gpositions;\n vector<short> weight;\...
1,331
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p> <p>Return the maximum amount of gold you can collect under the conditions:</p> <ul> <li>Every time you are located in a cell you will ...
3
{ "code": "using pt = pair<int, int>;\nusing ppt = pair<pt, int>;\n\nconst int dx[] = {-1, 0, 0, 1};\nconst int dy[] = {0, -1, 1, 0};\n\n// int dp[1 << 25];\n\nclass Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n vector<pt> gpositions;\n vector<int> weight;\n int n = g...