id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n int n = s.length(), val = 0;\n string temp = \"\";\n map<string,int> mp;\n for (int i = 0; i+k-1<n; i++) {\n temp = s.substr(i,k);\n if (!mp.count(temp)) {\n mp[temp] = 1;\n...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n string c=\"\";\n int n=s.length();\n map<string,int> binary;\n for(int i=0;i<=n-k;i++)\n {\n c= s.substr(i, k);\n binary[c]++; \n }\n if(binary.size()==pow(2,k))return true;\...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n int hasAllCodes(string s, int k) {\n map<string,int> tot;\n int n=s.length();\n for(int i=0;i<n-k+1;i++){\n string ss=\"\";\n for(int j=i;j<i+k;j++){\n ss+=s[j];\n }\n tot[ss]++;\n }\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n map<string,int> mp;\n int n;\n n=s.length();\n int g;\n g=(1<<k);\n string a;\n for(int i=0;i<n-k+1;i++)\n {\n a=s.substr(i,k);\n mp[a]++;\n }\n i...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n map<string,int> count;\n if(s.length() < k){\n return false;\n }\n\n for(int i=0;i<s.length()-k+1;i++){\n string temp=\"\";\n for(int j=0;j<k;j++){\n temp.push_ba...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n // Edge case: if k is greater than the length of s, return false\n if (k > s.length()) return false;\n\n int n = 1 << k;\n unordered_set<string> mp;\n for (int i = 0; i <= s.length() - k; i++) {\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n // this code consider the length of sustring of k and that can be made in s \n if (s.length() < k) return false;\n \n /* unordered_set<string> ss;\n int n = 1 << k; // 2^k\n\n for (int i = 0; i <= ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n //1-> 0 1\n //2-> 01 10 11 00\n //3->8\n //4->16\n //5->32\n unordered_map<string,int>mp;\n int n=s.length();\n if(k>n)return false;\n for(int i=0;i<n-k+1;i++){\n s...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n if(k > s.length()) return false;\n \n unordered_set<string>binaryCodes;\n int numBinaryCodes = 1 << k;\n int start = 0, end = 0;\n string binaryCode = \"\";\n\n while(end < s.length()){\n ...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n unordered_set<string>binaryCodes;\n int numBinaryCodes = pow(2,k);\n int start = 0, end = 0;\n string binaryCode = \"\";\n\n while(end < s.length()){\n binaryCode += s[end];\n if(en...
1,557
<p>Given a binary string <code>s</code> and an integer <code>k</code>, return <code>true</code> <em>if every binary code of length</em> <code>k</code> <em>is a substring of</em> <code>s</code>. Otherwise, return <code>false</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Inp...
3
{ "code": "class Solution {\npublic:\n string find(int n, int k){\n string ans = \"\";\n while(n>0){\n if(n&1)ans +=\"1\";\n else ans += \"0\";\n n = n/2;\n }\n while(ans.size()<k)ans += \"0\";\n return ans;\n }\n bool hasAllCodes(string s, ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int rows = grid.size(); \n int cols = grid[0].size();\n int dp[2][cols][cols]; // init to maximum size\n // std::cout << \"test\" << std::endl;\n // std::vector<std::vector<std::vector<int>>> ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int rows = grid.size(); \n int cols = grid[0].size();\n int dp[2][cols][cols]; // init to maximum size\n // std::cout << \"test\" << std::endl;\n // std::vector<std::vector<std::vector<int>>> ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n // Disable synchronization between C and C++ standard streams for faster I/O\n ios_base::sync_with_stdio(false);\n // Untie cin and cout from each other to prevent flushes on cin/cout calls\n cin.tie(...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n size_t cols = grid[0].size();\n auto dp_index = [=](vector<int>& dp, size_t r1, size_t r2) -> int& {\n return dp[r1 + r2 * cols];\n };\n\n vector<int> dp1(cols * cols, -1);\n vector<...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n vector<vector<int>> front(n, vector<int>(n,0));\n vector<vector<int>> cur(n, vector<int>(n,0));\n\n for(int j1=0; j1<n; j1++){\n for(...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n // int f(int i, int j1, int j2, vector<vector<int>>& grid,vector<vector<vector<int>>> &dp) {\n // int m = grid[0].size(), n = grid.size();\n // if (j1 < 0 || j1 >= m || j2 < 0 || j2 >= m)\n // return -1e8;\n // if (i == n - 1) {\n // ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n\n vector<vector<int>> grid;\n\n bool isValid(int x, int y)\n {\n if(x<0 || y<0 || x>=grid.size() || y>=grid[0].size())\n return false;\n return true;\n }\n\n bool isValid(int x1, int y1, int x2, int y2)\n {\n return isValid(x1, y...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n\n vector<vector<int>> grid;\n\n bool isValid(int x, int y)\n {\n if(x<0 || y<0 || x>=grid.size() || y>=grid[0].size())\n return false;\n return true;\n }\n\n bool isValid(int x1, int y1, int x2, int y2)\n {\n return isValid(x1, y...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int dp[70][70][70];\n int row, col;\n int solve(int r, int c0, int c1, vector<vector<int>>& grid) {\n if (r >= row || c0 < 0 || c0 >= col || c1 < 0 || c1 >= col)\n return 0;\n\n if (dp[r][c0][c1] != -1)\n return dp[r][c0][c1];\n\n ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int dp[80][80][80]; \n vector<vector<int>> g; \n int n, m; \n int rec(int i, int j, int b) {\n if(i == n){\n return 0; \n } \n if(dp[i][j][b] != -1) {\n return dp[i][j][b]; \n }\n\n int ans = g[i][j] + g[i][b];...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int dp[71][71][71]={[0 ... 70][0 ... 70][0 ... 70]=INT_MIN};\n int n=grid.size();\n int m=grid[0].size();\n dp[0][0][m-1]=grid[0][0]+grid[0][m-1];\n for(int i=1;i<n;i++){\n for(int j...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n long long dp[70][70][70]; // Adjust size according to constraints\n\n long long compute(int row, int col1, int col2, vector<vector<int>>& grid, int m, int n) {\n // base case\n if (col1 < 0 || col1 >= n || col2 < 0 || col2 >= n) return LLONG_MIN / 2; // chec...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "#define ll long long int \nclass Solution {\npublic:\n ll N, M;\n ll arr[71][71][71]; // Uncomment and use this for memoization\n\n ll help(vector<vector<int>>& v, int i, int j, int c) {\n int r =i;\n if (r < 0 || c < 0 || r >= N || c >= M || i < 0 || j < 0 || i >= N || j >= M)\n ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int dp[100][100][100];\n int f(int i, int j, int l, int n, int m ,vector<vector<int>>& grid)\n {\n if(i<0 || i>=n || j<0 || j>=m )\n return 0;\n if( l<0 || l>=m)\n return 0;\n if(dp[i][j][l]!=-1)\n return dp[i][j][...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int dp[101][101][101];\n int dfs(int row,int col1,int col2,vector<vector<int>>&grid){\n int m = grid.size();\n int n = grid[0].size();\n if(row==m) return 0;\n if(dp[row][col1][col2]!=-1) return dp[row][col1][col2];\n int ans = grid[row][...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\n int dp[101][101][101];\n int rows, cols;\n int solve(int r, int c1, int c2, vector<vector<int>>& grid){\n if(c1 < 0 || c2 < 0 || c1 >= cols || c2 >= cols || c1 == c2) return 0;\n if(r == rows-1){\n return grid[r][c1] + grid[r][c2];\n }\n i...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\nint dp[101][101][101];\n int f(vector<vector<int>>& grid, int m, int n, int i, int j1, int j2) {\n if (i < 0 || j1 < 0 || j2 < 0 || i > m - 1 || j1 > n - 1 ||\n j2 > n - 1) {\n return -1e8;\n }\n if (i == m - 1) {\n if (j1 ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n\n int dp[105][105][105];\n int f(int i,int j1,int j2,int r,int c,vector<vector<int>>& grid){\n // base cases\n // out of bound\n if(j1<0 || j2<0 || j1>=c || j2>=c){\n return -1e8;\n }\n // dp. check\n\n if(dp[i][j1][j2] ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n ssize_t cols = grid[0].size();\n auto dp_index = [&](vector<int>& dp, size_t r1, size_t r2) -> int& {\n return dp[r1 + r2 * cols];\n };\n\n std::vector<int> dp(cols * cols, -1);\n dp...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "int dy[] = {-1,0,1};\nclass Solution {\n int helper(int x1,int y1,int y2,int n,int m,vector<vector<int>> &v,int ***dp)\n {\n if(x1 >= n)\n return 0;\n \n if(dp[x1][y1][y2] != -1)\n return dp[x1][y1][y2];\n \n int res = 0;\n res += v[x1][...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\n int m, n;\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n m = grid.size();\n n = grid[0].size();\n vector<vector<int>> dp(n, vector<int>(n, INT_MIN/2));\n dp[0][n-1] = grid[0][0] + grid[0][n-1];\n\n for(int r=1; r<m; r++){\n ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int n=grid.size(),m=grid[0].size();\n vector<vector<vector<int>>> dp(n,vector<vector<int>>(m,vector<int>(m,-1e8)));\n return max(0,help(n,m,grid,dp,0,0,m-1));\n }\n int help(int n,int m,vector<vector<i...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n //TC: O(M*N*N*9)\n //SC: O(M*N*N)\n int m=grid.size();\n int n=grid[0].size();\n vector<vector<vector<int>>> dp(m,vector<vector<int>> (n,vector<int>(n,-1)));\n for(int j1=0;j1<n;j1++){\n...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
0
{ "code": "class Solution {\npublic:\n int cherryPickupHelper(vector<vector<int>>& grid , int i , int j1 , int j2 , int m , int n , vector<vector<vector<int>>>& dp){\n if(i == m || j1 < 0 || j2 < 0 || j1 == n || j2 == n) return -1e9;\n if(i == m-1){\n if(j1 == j2) return grid[i][j1];\n ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
1
{ "code": "class Solution {\npublic:\n int solve(vector<vector<int>>& grid, vector<vector<vector<int>>> &dp, int i, int j, int k){\n int m = grid.size();\n int n = grid[0].size();\n\n if(i==m) return 0;\n if(j<0 || j==n || k<0 || k==n) return -1e9;\n\n if(dp[i][j][k]!=-1) return ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
1
{ "code": "class Solution {\n /*\n robot 1 can have its own maximum path and robot 2 can have its own maximum path\n So what if we want to find their maximum values separately\n but we cannot do that in one recursive function it will be very messy or not possible\n lets say we argue that in one functio...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
1
{ "code": "class Solution {\npublic:\n int helper(vector<vector<int>> &grid,int row,int col1,int col2,vector<vector<vector<int>>> &dp){\n if(col1<0 || col1==grid[0].size() || col2<0 || col2==grid[0].size()){\n return INT_MIN;\n }\n if(row==grid.size()-1){\n if(col1==col2)...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
1
{ "code": "class Solution {\npublic:\n int solve(int i,int j1,int j2,vector<vector<int>>& grid,vector<vector<vector<int>>>& dp){\n if(j1<0 || j2<0 || j1>=grid[0].size() || j2>=grid[0].size()){\n return -1e8;\n }\n if(i==grid.size()-1){\n if(j1==j2){\n retur...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
2
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n vector<vector<vector<int>>> dp(n,vector<vector<int>>(m,vector<int>(m)));\n for(int i=0;i<m;i++){\n for(int j=0;j<m;j++){\n ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> mat;\n int n;\n int m;\n vector<vector<vector<int>>> dp; // Memoization table\n\n int solve(int i, int j, int k) {\n // Base case: if we reach beyond the last row\n if (i >= n) {\n return 0;\n }\n\n // Che...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n vector<vector<int>> pre(n, vector<int>(n, 0));\n for(int i = m - 1; i >= 0; i--) {\n vector<vector<int>> cur(n, vector<int>(n, 0));\n for(int ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<vector<int>>> dp (n , vector<vector<int>> (m+1 , vector<int> (m+1 , INT_MIN)));\n if (m-1>0){\n dp[0][0][m-1] = grid[0][0] + g...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int solve(vector<vector<int>>& nums, int i, int j1, int j2, vector<vector<vector<int>>>& dp) {\n if (j1 < 0 || j1 >= nums[0].size() || j2 < 0 || j2 >= nums[0].size() || j1 == j2) return 0;\n \n if (i == nums.size() - 1) return dp[i][j1][j2] = nums[i][j1] ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\nprivate:\n int solve(vector<vector<int>>& grid, int i, int j1, int j2, vector<vector<vector<int>>>& dp){\n if(j1 < 0 || j2 < 0 || j1 > grid[0].size()-1 || j2 > grid[0].size()-1) return -1e8;\n if(i == grid.size()-1){\n if(j1 == j2) return grid[i][j1];\n ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int rows = grid.size();\n int cols = grid[0].size();\n\n vector<vector<int>> dp(cols + 2, vector<int>(cols + 2));\n\n for (int i = rows - 1; i >= 0; i--) {\n vector<vector<int>> next_dp(col...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int m=grid.size();\n int n=grid[0].size();\n vector<vector<vector<int>>>dp(m+1,vector<vector<int>>(n+2,vector<int>(n+2,INT_MIN)));\n for(int i=0;i<=n+1;i++){\n for(int j=0;j<=n+1;j++){\n ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "\nclass Solution {\npublic:\n long long solve(vector<vector<int>> &grid, int i, int j1, int j2, vector<vector<vector<long long>>> &dp) {\n int n = grid.size();\n int m = grid[0].size();\n \n if(j1 < 0 || j1 >= m || j2 < 0 || j2 >= m) {\n return -1e9;\n }\n\n...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "#include <algorithm>\n#include <climits> // For LLONG_MIN\n#include <vector>\n\nusing namespace std;\n\nclass Solution {\npublic:\n long long ans(int i, int j1, int j2, vector<vector<int>>& grid,\n vector<vector<vector<long long>>>& dp) {\n int n = grid.size();\n int m = g...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "#include <vector>\n#include <algorithm>\n#include <climits> // For LLONG_MIN\n\nusing namespace std;\n\nclass Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n\n // Initialize memoization table\n vector<vect...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "#include <algorithm>\n#include <climits> // For LLONG_MIN\n#include <vector>\n\nusing namespace std;\n\nclass Solution {\npublic:\n long long ans(int i, int j1, int j2, vector<vector<int>>& grid,\n vector<vector<vector<long long>>>& dp) {\n int n = grid.size();\n int m = g...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int f(int i, int j1, int j2, vector<vector<int>>& grid, vector<vector<vector<long>>> &dp) {\n if(i>=grid.size() || j1>=grid[0].size() || j2>=grid[0].size()) return 0;\n if(dp[i][j1][j2] != -1) return dp[i][j1][j2];\n\n if(i==(grid.size()-1)) {\n ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int f(int i, int j1, int j2, vector<vector<int>>& grid, vector<vector<vector<long>>> &dp) {\n if(i>=grid.size() || j1>=grid[0].size() || j2>=grid[0].size()) return 0;\n if(dp[i][j1][j2] != -1) return dp[i][j1][j2];\n\n if(i==(grid.size()-1)) {\n ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<vector<long>>> dp(n+1, vector<vector<long>>(m+1, vector<long>(m+1, 0)));\n\n for(int j=0;j<m;j++){\n for(int j1=0;j1<m;j1++){\...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int rows = grid.size();\n int cols = grid[0].size();\n\n // Initialize a 3D DP table\n vector<vector<vector<int>>> dp(rows, vector<vector<int>>(cols, vector<int>(cols, -1)));\n dp[0][0][cols - ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int rows = grid.size(); // Number of rows in the grid\n int cols = grid[0].size(); // Number of columns in the grid\n\n // Initialize a 3D DP table\n // dp[r][c1][c2] will store the maximum cherries c...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int n=grid.size(),m=grid[0].size();\n vector<vector<vector<int>>> dp(n,vector<vector<int>>(m,vector<int>(m,-1e8)));\n return help(n,m,grid);\n }\n int help(int n,int m,vector<vector<int>>& grid){\n ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<vector<int>>> dp(n, vector<vector<int>> (m, vector<int> (m, -1))); // {i, {j1, j2}}\n vector<vector<int>> nextMatrix(m, vector<int> (m...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\nint solve_tab(vector<vector<int>> grid)\n{\n int n=grid.size();\n int m=grid[0].size();\n vector<vector<vector<int>>> dp(n,vector<vector<int>>(m,vector<int>(m,-1)));\n for(int j1=0;j1<m;j1++)\n {\n for(int j2=0;j2<m;j2++)\n {\n if(j1==j2)\n...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "int desync = []{\n ios::sync_with_stdio(0);\n cin.tie(0);\n return 0;\n}();\nstruct Robot_format {\n int P_R1;\n int P_R2;\n int sum;\n Robot_format() : P_R1(), P_R2(), sum() {}\n Robot_format(int x, int y, int z) : P_R1(x), P_R2(y), sum(z) {}\n};\nclass Solution {\npublic:\n int cherryPic...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "\nstruct Robot_format {\n int Robot_1_position;\n int Robot_2_position;\n int sum;\n Robot_format() : Robot_1_position(), Robot_2_position(), sum() {}\n Robot_format(int x, int y, int z) : Robot_1_position(x), Robot_2_position(y), sum(z) {}\n};\nclass Solution {\npublic:\n int cherryPickup(vector<v...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n struct Robot_format {\n int Robot_1_position;\n int Robot_2_position;\n int sum;\n Robot_format() : Robot_1_position(), Robot_2_position(), sum() {}\n Robot_format(int x, int y, int z) :...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "int desync = []{\n ios::sync_with_stdio(0);\n cin.tie(0);\n return 0;\n}();\nstruct Robot_format {\n int P_R1;\n int P_R2;\n int sum;\n Robot_format() : P_R1(), P_R2(), sum() {}\n Robot_format(int x, int y, int z) : P_R1(x), P_R2(y), sum(z) {}\n};\nclass Solution {\npublic:\n int cherryPic...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "int desync = []{\n ios::sync_with_stdio(0);\n cin.tie(0);\n return 0;\n}();\nstruct Robot_format {\n int Robot_1_position;\n int Robot_2_position;\n int sum;\n Robot_format() : Robot_1_position(), Robot_2_position(), sum() {}\n Robot_format(int x, int y, int z) : Robot_1_position(x), Robot_2_...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "int desync = []{\n ios::sync_with_stdio(0);\n cin.tie(0);\n return 0;\n}();\nstruct Robot_format {\n int P_R1;\n int P_R2;\n int sum;\n Robot_format() : P_R1(), P_R2(), sum() {}\n Robot_format(int x, int y, int z) : P_R1(x), P_R2(y), sum(z) {}\n};\nclass Solution {\npublic:\n int cherryPic...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n bool is_valid(int r, int c, int N, int M) {\n return (0 <= r && r < N) && (0 <= c && c < M);\n }\n bool is_same(int r1, int c1, int r2, int c2) {\n return r1 == r2 && c1 == c2;\n }\n int dp[73][73][73];\n int solve(int row1, int col1, int row2, in...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "int dp[71][71][71];\nclass Solution {\npublic:\n int solve(int r, int c1, int c2, vector<vector<int>>&grid)\n {\n int n=grid.size(); int m=grid[0].size();\n if(r==n-1)\n {\n if(c1==c2) return dp[r][c1][c2]=grid[r][c1];\n else return dp[r][c1][c2]=grid[r][c1...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "int desync = []{\n ios::sync_with_stdio(0);\n cin.tie(0);\n return 0;\n}();\nstruct Robot_format {\n int row;\n int Robot_1_position;\n int Robot_2_position;\n int sum;\n Robot_format() : row(), Robot_1_position(), Robot_2_position(), sum() {}\n Robot_format(int r, int x, int y, int z) : row...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "int desync = []{\n ios::sync_with_stdio(0);\n cin.tie(0);\n return 0;\n}();\nstruct Robot_format {\n int row;\n int Robot_1_position;\n int Robot_2_position;\n int sum;\n Robot_format() : row(), Robot_1_position(), Robot_2_position(), sum() {}\n Robot_format(int r, int x, int y, int z) : row...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "int desync = []{\n ios::sync_with_stdio(0);\n cin.tie(0);\n return 0;\n}();\nstruct Robot_format {\n int Robot_1_position;\n int Robot_2_position;\n int sum;\n Robot_format() : Robot_1_position(), Robot_2_position(), sum() {}\n Robot_format(int x, int y, int z) : Robot_1_position(x), Robot_2_...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "int desync = []{\n ios::sync_with_stdio(0);\n cin.tie(0);\n return 0;\n}();\nstruct Robot_format {\n int Robot_1_position;\n int Robot_2_position;\n int sum;\n Robot_format() : Robot_1_position(), Robot_2_position(), sum() {}\n Robot_format(int x, int y, int z) : Robot_1_position(x), Robot_2_...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "\nclass Solution {\npublic:\nint a[100][100][100];\nint f(int i , int j , int jj , vector<vector<int>>& grid){\n int n = grid.size();\n int m = grid[0].size();\n\n if(i>=n)return 0;\n\n if(a[i][j][jj]!=-1)return a[i][j][jj];\n\n\n // cout<<i<<\" \"<<j<<\" \"<<jj<<endl;\n\n\n int ans = 0;\...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\n int solve(int row, int col1, int col2, int n, int m, vector<vector<int>>& grid, vector<vector<vector<int>>> &dp) {\n if(col1<0 || col2<0 || col1>=m || col2>=m)\n return INT_MIN;\n\n if(row == n-1) {\n if(col1 == col2)\n return grid[ro...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int solve(int i , int j1 , int j2 , vector<vector<int>>& grid , int last_row , int last_col , vector<vector<vector<int>>>& dp){\n if(j1 < 0 || j2 > last_col || j1 > last_col || j2 < 0){\n return -1e8;\n }\n if(i == last_row){\n if(j1...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "/* tle with recursion\nclass Solution {\npublic:\n\n int helper(int row, int colA, int colB, vector<vector<int>>& grid){\n if(row == grid.size()-1){\n if(colA == colB) return grid[row][colA];\n else return grid[row][colA] + grid[row][colB];\n }\n vector<int> di...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<vector<int>>> dp(m, vector<vector<int>>(m, vector<int>(2, -1)));\n int curr = 1, prev = 0;\n dp[0][m-1][0] = grid[0][0] + grid[0][...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int solve(int y1, int x, int y2, vector<vector<int>>& grid, vector<vector<vector<int>>>&dp) {\n if(x >= grid.size() || y1 < 0 || y2 < 0 || y1 >= grid[0].size() || y2 >= grid[0].size()) return 0;\n if(dp[x][y1][y2] != -1) return dp[x][y1][y2];\n\n vector<...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int solve(vector<vector<int>>&grid,int i,int j1,int j2, vector<vector<vector<int>>> &dp)\n {\n int n = grid.size();\n int m = grid[0].size();\n \n if(i==n-1)\n {\n if(j1==j2)\n {\n return grid[i][j1];\n ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int solve(vector<vector<int>>& grid, int row, int col1,int col2,vector<vector<vector<int>>> &dp){\n if(row==grid.size() || col1==grid[0].size() || col2==grid[0].size() || row<0 || col1<0 || col2<0){\n return INT_MIN;\n }\n if(row==grid.size()-1...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int solve(vector<vector<int>>& grid, int row, int col1,int col2,vector<vector<vector<int>>> &dp){\n if(row==grid.size() || col1==grid[0].size() || col2==grid[0].size() || row<0 || col1<0 || col2<0){\n return INT_MIN;\n }\n if(dp[row][col1][col2...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int solve(vector<vector<int>>& grid, int row, int col1,int col2,vector<vector<vector<int>>> &dp){\n if(row==grid.size() || col1==grid[0].size() || col2==grid[0].size() || row<0 || col1<0 || col2<0){\n return INT_MIN;\n }\n if(row==grid.size()-1...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int help(int i, int j, int a, int b, vector<vector<int>>& grid, int n, int m,vector<vector<vector<int>>>& dp ) {\n if(j<0 || b<0 || j>=m || b>=m) {\n return -1e8;\n }\n if(i==n) {\n return 0;\n }\n if(dp[i][j][b] != -1)...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n int rowNum = grid.size();\n int colNum = grid[0].size();\n unordered_map<int, int> mp{};\n mp[0*1000+colNum-1] = grid[0][0] + grid[0][colNum-1];\n int res{};\n for(int r=1; r<rowNum; r++...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n int solve(vector<vector<int>>& grid, vector<vector<vector<int>>> &dp, int i, int j, int k){\n int m = grid.size();\n int n = grid[0].size();\n\n if(i==m) return 0;\n if(j<0 || j==n || k<0 || k==n) return -1e9;\n\n if(dp[i][j][k]!=-1) return ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "int max_cherry(int r,int c1,int c2,vector<vector<int>> &grid, vector<vector<vector<int>>> &dp){\n int n=grid.size();\n int m=grid[0].size();\n if(c1<0 || c1>=m || c2<0 || c2>=m) return 0;\n if(r>=grid.size()){\n return 0;\n }\n if(dp[r][c1][c2]!=-1) return dp[r][c1][c2];\n int c...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n typedef vector<vector<vector<int>>> v3;\n int rec(int r,int c1,int c2,vector<vector<int>>& grid,v3& dp){\n if (c1 == grid[0].size() || c2 == grid[0].size() || c1 < 0 || c2 < 0)\n return INT_MIN;\n if (r==grid.size())\n return 0;\n ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n\n int pick(vector<vector<int>>& grid, int row, int r1, int r2, map<pair<pair<int,int>,int>,int>& mem) {\n if(mem.find(pair(pair(r1,r2),row)) != mem.end()) {\n return mem[pair(pair(r1,r2),row)];\n }\n \n if(r1==r2) {\n return -...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n\n int solve(int i, int j1, int j2,vector<vector<vector<int>>>& dp, vector<vector<int>>& grid){\n int n = grid.size();\n int m = grid[0].size();\n if(j1>=m || j1<0 || j2>=m || j2<0){\n return INT_MIN;\n }\n if(i==n-1){\n ...
1,559
<p>You are given a <code>rows x cols</code> matrix <code>grid</code> representing a field of cherries where <code>grid[i][j]</code> represents the number of cherries that you can collect from the <code>(i, j)</code> cell.</p> <p>You have two robots that can collect cherries for you:</p> <ul> <li><strong>Robot #1</st...
3
{ "code": "class Solution {\npublic:\n\n int solve(int i, int j1, int j2,vector<vector<vector<int>>>& dp, vector<vector<int>>& grid){\n int n = grid.size();\n int m = grid[0].size();\n if(j1>=m || j1<0 || j2>=m || j2<0){\n return INT_MIN;\n }\n if(i==n-1){\n ...
1,574
Given the array of integers <code>nums</code>, you will choose two different indices <code>i</code> and <code>j</code> of that array. <em>Return the maximum value of</em> <code>(nums[i]-1)*(nums[j]-1)</code>. <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,4,5,2...
0
{ "code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n int biggest = nums[0];\n int biggest2 = 0;\n for(int i = 1; i< nums.size(); i++){\n if(nums[i] > biggest){\n biggest2 = biggest;\n biggest = nums[i];\n }else if(nums...
1,574
Given the array of integers <code>nums</code>, you will choose two different indices <code>i</code> and <code>j</code> of that array. <em>Return the maximum value of</em> <code>(nums[i]-1)*(nums[j]-1)</code>. <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,4,5,2...
0
{ "code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n int mx=0;\n\n int x=nums.size();\n \n for(int i=0;i<x;i++)\n {\n for(int j=i+1;j<x;j++)\n {\n int s=(nums[i]-1)*(nums[j]-1);\n if(s>mx)\n ...
1,574
Given the array of integers <code>nums</code>, you will choose two different indices <code>i</code> and <code>j</code> of that array. <em>Return the maximum value of</em> <code>(nums[i]-1)*(nums[j]-1)</code>. <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,4,5,2...
0
{ "code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n int sum=1;\n for(int i=0; i<nums.size()-1; i++){\n int min=i;\n for(int j=i+1; j<nums.size(); j++){\n if(nums[j]>nums[min]){\n min=j;\n }\n }\...
1,574
Given the array of integers <code>nums</code>, you will choose two different indices <code>i</code> and <code>j</code> of that array. <em>Return the maximum value of</em> <code>(nums[i]-1)*(nums[j]-1)</code>. <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,4,5,2...
0
{ "code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n int maxi = INT_MIN;\n int smaxi = INT_MIN;\n for (int i = 0; i < nums.size(); i++)\n {\n if (maxi < nums[i])\n {\n smaxi = maxi;\n maxi = nums[i];\n ...
1,574
Given the array of integers <code>nums</code>, you will choose two different indices <code>i</code> and <code>j</code> of that array. <em>Return the maximum value of</em> <code>(nums[i]-1)*(nums[j]-1)</code>. <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,4,5,2...
0
{ "code": "class Solution {\npublic:\nint maxvalue(vector<int>&nums)\n{\n int firstmax=INT_MIN;\n int secondmax=INT_MIN;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]>firstmax)\n {\n secondmax=firstmax;\n firstmax=nums[i];\n }\n else if(nums[i]>=second...
1,574
Given the array of integers <code>nums</code>, you will choose two different indices <code>i</code> and <code>j</code> of that array. <em>Return the maximum value of</em> <code>(nums[i]-1)*(nums[j]-1)</code>. <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,4,5,2...
0
{ "code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n int max1 = INT_MIN;\n int max2 = INT_MIN;\n int n = nums.size();\n for(int i=0; i<n; i++){\n if(max1 <= nums[i]){\n max2 = max1;\n max1 = nums[i];\n }\n ...
1,574
Given the array of integers <code>nums</code>, you will choose two different indices <code>i</code> and <code>j</code> of that array. <em>Return the maximum value of</em> <code>(nums[i]-1)*(nums[j]-1)</code>. <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,4,5,2...
0
{ "code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n int maxi = INT_MIN;\n int smaxi = INT_MIN;\n int size = nums.size();\n for (int i = 0; i < size; i++)\n {\n if (maxi < nums[i])\n {\n smaxi = maxi;\n m...
1,574
Given the array of integers <code>nums</code>, you will choose two different indices <code>i</code> and <code>j</code> of that array. <em>Return the maximum value of</em> <code>(nums[i]-1)*(nums[j]-1)</code>. <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,4,5,2...
2
{ "code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n return (nums[nums.size()-1]-1) * (nums[nums.size()-2]-1);\n }\n};", "memory": "12800" }
1,574
Given the array of integers <code>nums</code>, you will choose two different indices <code>i</code> and <code>j</code> of that array. <em>Return the maximum value of</em> <code>(nums[i]-1)*(nums[j]-1)</code>. <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,4,5,2...
2
{ "code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n return (nums[nums.size()-1]-1) * (nums[nums.size()-2]-1);\n }\n};", "memory": "12800" }
1,574
Given the array of integers <code>nums</code>, you will choose two different indices <code>i</code> and <code>j</code> of that array. <em>Return the maximum value of</em> <code>(nums[i]-1)*(nums[j]-1)</code>. <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,4,5,2...
2
{ "code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int a = nums.back();\n nums.pop_back();\n int b = nums.back();\n nums.pop_back();\n return (a-1)*(b-1);\n }\n};", "memory": "12900" }
1,574
Given the array of integers <code>nums</code>, you will choose two different indices <code>i</code> and <code>j</code> of that array. <em>Return the maximum value of</em> <code>(nums[i]-1)*(nums[j]-1)</code>. <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,4,5,2...
2
{ "code": "class Solution {\npublic:\n int maxProduct(vector<int>& arr) {\n sort(arr.begin() , arr.end());\n\n int n = arr.size();\n\n int a= arr[n-1]-1;\n int b = arr[n-2]-1;\n\n int ans = a*b;\n return ans; \n }\n};", "memory": "12900" }