id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "\nclass Solution {\n\n int SolveByMemo(string &s , int &k , int index , int prev , vector<vector<int>> &dp)\n {\n if(index == s.length())\n return 0;\n\n if(dp[index][prev] != -1)\n return dp[index][prev];\n\n int op1 = 0 + SolveByMemo(s, k , index+1 , prev , dp);\n\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "\nclass Solution {\n\n int SolveByMemo(string &s , int &k , int index , int prev , vector<vector<int>> &dp)\n {\n if(index == s.length())\n return 0;\n\n if(dp[index][prev] != -1)\n return dp[index][prev];\n\n int op1 = 0 + SolveByMemo(s, k , index+1 , prev , dp);\n\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "\nclass Solution {\n\n int SolveByMemo(string &s , int &k , int index , int prev , vector<vector<int>> &dp)\n {\n if(index == s.length())\n return 0;\n\n if(dp[index][prev] != -1)\n return dp[index][prev];\n\n int op1 = 0 + SolveByMemo(s, k , index+1 , prev , dp);\n\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "\nclass Solution {\n\n int SolveByMemo(string &s , int &k , int index , int prev , vector<vector<int>> &dp)\n {\n if(index == s.length())\n return 0;\n\n if(dp[index][prev] != -1)\n return dp[index][prev];\n\n int op1 = 0 + SolveByMemo(s, k , index+1 , prev , dp);\n\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\npublic:\nvector<vector<int>> dp;\nint solve(string &s , int &k , int i , int prev)\n{\n if(i == s.size()) return 0;\n if(dp[i][prev+1]!=-1) return dp[i][prev+1];\n int notpick = solve(s , k , i+1 , prev);\n int pick = 0;\n if(abs(s[i]-prev-'a') <=k || prev == -1 ){ pick = 1... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\n private:\n int solve(int i, int c ,string &s,int k ,vector<vector<int>>&dp){\n if(i == s.size())return 0;\n if(dp[i][c] != -1)return dp[i][c];\n \n int take = 0;\n if(c == 27 || abs((s[i]-'a') - c ) <= k){\n take ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\npublic:\n int solve(int i,int p,string& s,int k,vector<vector<int>>& dp){\n if(i>=s.size()) return 0;\n if(dp[i][p+1]!=-1) return dp[i][p+1];\n int d=s[i]-'a';\n int ans=0,ans1=0;\n if(p==-1){\n ans=1+solve(i+1,s[i]-'a',s,k,dp);\n }e... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\npublic:\n int rec(int i, int ch, string&s,int k,vector<vector<int>>&dp){\n int n=s.length();\n if(i==n){\n return 0;\n }\n\n if(dp[i][ch]!=-1){\n return dp[i][ch];\n }\n\n int ans=0;\n\n if(ch==30){ //picking first... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\n private:\n int f(int t, char c, int k, string &s,vector<vector<int>>&dp){ \n int n = s.size();\n if(t<0){\n return 0;\n }\n if(dp[t][c-'a']!=-1){\n return dp[t][c-'a'];\n }\n int nt ... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n\n int dim1 = grid.size()-2;\n int dim2 = grid[0].size()-2;\n vector<vector<int>> ans(dim1,vector<int>(dim2,0));\n\n for(int x = 0; x < dim1; x++){\n for(int y = 0; y < dim2;... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n #define MAX(a, b) ((a) > (b) ? (a) : (b))\n #define MAX_3(a, b, c) ((a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c)))\n int m(grid.size()), n(grid[0].size());\n for (int i... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 0 | {
"code": "class Solution {\npublic:\n int largestValue(vector<vector<int>>& grid, int r, int c)\n {\n int maxValue = 0;\n for (int i=r;i<r+3;i++)\n {\n for(int j=c; j<c+3; j++)\n {\n maxValue=max(maxValue,grid[i][j]);\n }\n }\n\n ... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 0 | {
"code": "class Solution {\npublic:\n int highest_val(vector<vector<int>>&grid, int k, int l)\n {\n int high_val = 0;\n for(int i= k; i< k+3; i++)\n {\n for(int j=l; j< l+3; j++)\n {\n high_val = max(high_val, grid[i][j]);\n ... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 0 | {
"code": "class Solution {\npublic:\n int findLocalMax(vector<vector<int>>& grid,int row,int col)\n {\n int maxVal=INT_MIN;\n for(int x=row;x<=row+2;x++)\n {\n for(int y=col;y<=col+2;y++)\n {\n maxVal=max(maxVal,grid[x][y]);\n }\n }\n ... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 0 | {
"code": "class Solution {\npublic:\n int f(int i,int j,vector<vector<int>>& grid){\n int ans = INT_MIN;\n for(int x = i;x<i+3;x++){\n for(int y = j;y<j+3;y++){\n ans = max(ans,grid[x][y]);\n }\n }\n return ans;\n\n }\n vector<vector<int>> lar... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 0 | {
"code": "class Solution {\r\npublic:\r\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\r\n int n = grid.size();\r\n vector<vector<int>> res(n-2, vector<int>(n-2));\r\n for (int i=1; i < n-1; i++)\r\n {\r\n for (int j=1; j < n-1; j++)\r\n {\r\n ... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 2 | {
"code": "class Solution {\npublic:\n int f(int i,int j,vector<vector<int>>& grid){\n int ans = INT_MIN;\n for(int x = i;x<i+3;x++){\n for(int y = j;y<j+3;y++){\n ans = max(ans,grid[x][y]);\n }\n }\n return ans;\n\n }\n vector<vector<int>> lar... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n int y = grid.size();\n std::vector<std::vector<int>> inner(y- 2);\n for (int i = 0; i < y - 2; i++){\n std::vector<int> row(y - 2);\n for (int j = 0; j < y- 2; j++){\n ... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n #define MAX_3(a, b, c) ((a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c)))\n int m(grid.size()), n(grid[0].size());\n for (int i = 0; i < m; i ++) {\n vector<int> tmp(n... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n #define MAX(a, b) ((a) > (b) ? (a) : (b))\n #define MAX_3(a, b, c) ((a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c)))\n int m(grid.size()), n(grid[0].size());\n for (int i... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<vector<int>> rowMax(n, vector<int>(n - 2));\n vector<vector<int>> maxLocal(n - 2, vector<int>(n - 2));\n\n for (int i = 0; i < n; ++i) {\n for ... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n\n //vector<vector<int>> answer(grid.size()-2, vector<int>(grid.size()-2));\n vector<vector<int>> answer;\n\n for(int i = 0; i < grid.size()-2; i++) {\n\n vector<int> arr;\n ... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n vector<vector<int>> res;\n\n int maxEle;\n for(int row = 0; row < grid.size() - 2; ++row){\n vector<int> tmp;\n for(int col = 0; col < grid[0].size() - 2; ++col){\n ... |
2,454 | <p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
<ul>
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</co... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n vector<vector<int> > ans;\n int n = grid.size();\n int m = grid[0].size();\n for(int i =0;i<=n-3;i++){\n vector<int>temp;\n for(int j =0;j<=m-3;j++){\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n vector<int> nums;\n vector<char> op;\n int size = expression.size();\n for(int i=0;i<size;) {\n int c = 0;\n while(i<size && !(expression[i]=='-' || expression[i]=='+' || ex... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n vector<int> data;\n vector<char> ops;\n istringstream ss(expression+\"+\");// \"+\"便于while()转换,不会用到\n int num = 0;\n char op = ' ';\n while(ss >> num && ss >> op) {\n dat... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n int func(int f,int s, char op){\n if(op=='+'){\n return f+s;\n }\n if(op=='-'){\n return f-s;\n }\n if(op=='*'){\n return f*s;\n }\n return 0;\n }\n vector<int> diffWaysToCompute(string s)... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n int n = expression.length();\n // Create a 2D array of vectors to store results of subproblems\n vector<vector<vector<int>>> dp(n, vector<vector<int>>(n));\n\n // Initialize the dp array with emp... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n // function calculates the result for each combination of left and right subarray\n void calVal(vector<int>& target, const vector<int>& ls, const vector<int>& rs, char op) {\n // passing in all the arguments as references to avoid return type\n for (const aut... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n int n = expression.size();\n vector<vector<vector<int>>> memoization(n+1, vector<vector<int>>(n+1, vector<int>()));\n diffWaysToCompute(expression, 0, n, memoization);\n return memoization[0][n];... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n void compute(std::vector<std::vector<std::vector<int>>>& vals, std::vector<int>& nums,\n std::vector<char>& ops, int l, int r) {\n std::cout << l << \" \" << r << std::endl;\n if (!vals[l][r].empty()) {\n return;\n }\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n int compute(int a,int b,char c){\n if(c=='*')\n return a*b;\n if(c=='+')\n return a+b;\n return a-b;\n }\n bool isOperator(char ch){\n if(ch=='+'||ch=='-'||ch=='*')\n return true;\n return false;\n }\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n int n = expression.length();\n // Create a 2D array of lists to store results of subproblems\n vector<vector<vector<int>>> dp(n, vector<vector<int>>(n));\n\n initializeBaseCases(expression, dp);\... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string s) {\n \n vector< pair<char, int> > arr;\n\n int n = s.length();\n\n for( int i=0; i<n; i++) {\n if((s[i]=='+') || (s[i]=='-') || (s[i]=='*')) {\n arr.push_back({ s[i], 0});\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n int n = expression.length();\n // Create a 2D array of lists to store results of subproblems\n vector<vector<vector<int>>> dp(n, vector<vector<int>>(n));\n\n initializeBaseCases(expression, dp);\... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n int n = expression.length();\n // Create a 2D array of lists to store results of subproblems\n vector<vector<vector<int>>> dp(n, vector<vector<int>>(n));\n\n initializeBaseCases(expression, dp);\... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n return helper(expression, 0, expression.size()-1);\n }\n\n vector<int> helper(string &expression, int st, int ed) {\n vector<int> ans;\n\n bool hasSymbol = false;\n\n for(int k=st+1;k<ed;k+... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n int n = expression.length();\n // Create a 2D array of lists to store results of subproblems\n vector<vector<vector<int>>> dp(n, vector<vector<int>>(n));\n\n initializeBaseCases(expression, dp);\... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n int evaluate(const int left, const int right, const char op) {\n switch (op) {\n case '+': return left + right;\n case '-': return left - right;\n default: return left * right;\n }\n }\n\n vector<int> helper(const int n, co... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n // Initialize memoization vector to store results of subproblems\n vector<vector<vector<int>>> memo(\n expression.length(), vector<vector<int>>(expression.length()));\n // Solve for the entir... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n\nvector<int> rec(int start,int end,string &e,vector<vector<vector<int>>>&dp){\n if(!dp[start][end].empty())return dp[start][end];\n vector<int>ans;\n if(start==end){\n ans.push_back(e[start]-'0');\n return ans;\n }\n if(end==start+1 && isdigit(e[star... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> dp[20][20];\n vector<int> convert(string& expression){\n vector<int> ans;\n int sz=expression.size();\n ans.reserve(sz);\n int x=0;\n for(int i=0; i<sz; i++){\n const char c=expression[i];\n switch(c){\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> dp[20][20];\n vector<int> convert(string& expression){\n vector<int> ans;\n int sz=expression.size();\n ans.reserve(sz);\n int x=0;\n for(int i=0; i<sz; i++){\n const char c=expression[i];\n switch(c){\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> dp[20][20];\n vector<int> convert(string& expression){\n vector<int> ans;\n int sz=expression.size();\n ans.reserve(sz);\n int x=0;\n for(int i=0; i<sz; i++){\n const char c=expression[i];\n switch(c){\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n map<pair<int,int>, vector<int>> dp;\n int calculate(int x, int y, char opr){\n int ans;\n switch(opr){\n case '+':\n ans = x + y;\n break;\n case '-':\n ans = x - y;\n break;\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> dp[20][20];\n vector<int> convert(string& expression){\n vector<int> ans;\n int sz=expression.size();\n ans.reserve(sz);\n int x=0;\n for(int i=0; i<sz; i++){\n const char c=expression[i];\n switch(c){\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n // Memoization map to store already computed results\n unordered_map<string, vector<int>> map;\n\n vector<int> diffWaysToCompute(string expression) {\n // Step 1: Check if the result for the current expression is already computed\n if (map.find(expression)... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n return dfs(expression);\n }\n\n vector<int> dfs(string exp) {\n if (memo.count(exp)) return memo[exp];\n if (exp.size() < 3) return {stoi(exp)};\n vector<int> ans;\n int n = exp.size... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n map<pair<int,int>,vector<int>>dp;\n vector<int> solve(int i,int j,string &s){\n if(j-i+1<=2){\n string temp=s.substr(i,(j-i+1));\n cout<<temp<<endl;\n return {stoi(temp)};\n }\n\n if(dp.count({i,j})>0) return dp[{i,j}];... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "struct ParseResult {\n std::vector<int> values;\n std::vector<char> operators;\n};\n\nclass Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n auto [values, operators] = parse(expression);\n // for (int x : values) std::cout << x << std::endl;\n // for ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> dp[20][20];\n vector<int> convert(string& expression){\n vector<int> ans;\n int sz=expression.size();\n ans.reserve(sz);\n int x=0;\n for(int i=0; i<sz; i++){\n const char c=expression[i];\n switch(c){\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n //dp[index1][index2]\n vector<int> solve(int index1, int index2, string expression, vector<vector<vector<int>>>& dp) {\n //base case\n if(index1 == index2) {\n return dp[index1][index2] = {expression[index1] - '0'};\n }\n if(index1 + ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n //dp[index1][index2]\n vector<int> solve(int index1, int index2, string expression, vector<vector<vector<int>>>& dp) {\n //base case\n if(index1 == index2) {\n return dp[index1][index2] = {expression[index1] - '0'};\n }\n if(index1 + ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n map<string,vector<int>> dp;\n vector<int> func(string q){\n if(dp.find(q)!=dp.end())\n return dp[q]; \n\n vector<int> ans;\n for(int i=0;i<q.size();i++){\n if(!(q[i]=='+' || q[i]=='-' || q[i]=='*'))\n continue;... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n map<string,vector<int>> dp;\n vector<int> func(string q){\n if(dp.find(q)!=dp.end())\n return dp[q]; \n\n vector<int> ans;\n for(int i=0;i<q.size();i++){\n if(!(q[i]=='+' || q[i]=='-' || q[i]=='*'))\n continue;... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\n\n map<pair<int, int>, vector<int>> cache; // (start, end) -> possible values\n\npublic:\n\n vector<int> diffWaysToComputePart(string expression, int start, int end) {\n \n if (this->cache.find({start, end}) != this->cache.end())\n return this->cache[{start... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\n public:\n vector<int> diffWaysToCompute(string expression) {\n return ways(expression, {});\n }\n\n private:\n vector<int> ways(const string& s, unordered_map<string, vector<int>>&& mem) {\n if (const auto it = mem.find(s); it != mem.cend())\n return it->second;\n\n vect... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> dfs(const string& expression, int i, int j, unordered_map<string, vector<int>>& memo) {\n string key = to_string(i) + \"_\" + to_string(j);\n if (memo.count(key)) {\n return memo[key];\n }\n\n bool isNumber = true;\n f... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\n public:\n vector<int> diffWaysToCompute(string expression) {\n return ways(expression, {});\n }\n\n private:\n vector<int> ways(const string& s, unordered_map<string, vector<int>>&& mem) {\n if (const auto it = mem.find(s); it != mem.cend())\n return it->second;\n\n vect... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n unordered_map<string, vector<int>> dp;\n\n vector<int> helper(string &s, int i, int j) {\n string key = to_string(i) + \",\" + to_string(j);\n if (dp.find(key) != dp.end()) return dp[key]; // Return cached result if it exists\n \n if (i > j) re... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n unordered_map<string, vector<int>> dp;\n\n vector<int> helper(string &s, int i, int j) {\n string key = to_string(i) + \",\" + to_string(j);\n if (dp.find(key) != dp.end()) return dp[key]; // Return cached result if it exists\n \n if (i > j) re... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\npublic:\n vector<int> helper(vector<int>& a, vector<int>& b, char op) {\n vector<int> ans;\n for (int x : a) {\n for (int y : b) {\n if (op == '+') ans.push_back(x + y);\n else if (op == '-') ans.push_back(x - y);\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\nprivate:\n std::unordered_map<std::string, std::vector<int>> memo;\n\n void parseExpression(const std::string& expression, std::vector<int>& numbers, std::vector<char>& operators) {\n int currentNumber = 0;\n for (char c : expression) {\n if (std::isdigit(c)... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 0 | {
"code": "class Solution {\nprivate:\n std::unordered_map<std::string, std::vector<int>> memo;\n\n void parseExpression(const std::string& expression, std::vector<int>& numbers, std::vector<char>& operators) {\n int currentNumber = 0;\n for (char c : expression) {\n if (std::isdigit(c)... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\nstring exp;\nunordered_map<int,unordered_map<int,vector<int>>> dp;\nvector<int> solve(int st,int e){\n if(dp[st].find(e)!=dp[st].end())\n return dp[st][e];\n if(st==e){\n return dp[st][e]={exp[st]-'0'};\n\n }\n if(e-st==1){\n return dp[st][e]={stoi(ex... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n return Partition(expression, 0, expression.size());\n }\n\n std::vector<int> Partition(std::string &exp, int left, int right) {\n int first_v = exp[left] - '0'; int left_front = left;\n if (std::i... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\n int op(int num1, int num2, char sym) const noexcept {\n switch(sym) {\n case '+':\n return num1 + num2;\n case '-':\n return num1 - num2;\n case '*':\n return num1 * num2;\n default:\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\n int op(int num1, int num2, char sym) const noexcept {\n switch(sym) {\n case '+':\n return num1 + num2;\n case '-':\n return num1 - num2;\n case '*':\n return num1 * num2;\n default:\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n vector<int> fun(vector<int>&v,int s,int e){\n if(s==e)\n return {v[s]};\n if(s+2==e){\n if(v[(s+e)/2]==-1)\n return {v[s]+v[e]};\n else if(v[(s+e)/2]==-2)\n return {v[s]-v[e]};\n else if(v... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\nprivate:\n int perform(int x, int y, char op) {\n if(op == '+') return x + y;\n if(op == '-') return x - y;\n if(op == '*') return x * y;\n return 0;\n }\n vector<int> solve(int start, int end, string &s){\n if(end==start) return {s[end]-'0'};\n... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n vector<int> operands;\n vector<char> operators;\n int idx = 0;\n while (idx < expression.length()) {\n if ('0' <= expression[idx] && expression[idx] <= '9') {\n operands... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n\n string s;\n int op(char c, int a, int b){\n if(c == '+'){\n return a+b;\n }else if(c == '-'){\n return a-b;\n }\n return a*b;\n }\n\n vector<int> rec(int l, int r){\n // if(l == r){\n // int x = s[... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n int op(int i,int j, char opcode)\n {\n if(opcode == '+')\n return i + j;\n if(opcode == '-')\n return i - j;\n if(opcode == '*')\n return i * j;\n return -1;\n }\n vector<int> solve(string& exp, int i, int ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n int n = expression.size();\n vector<vector<vector<int>>> memo(n, vector<vector<int>>(n));\n // memo[i][j] means from i-th to j-th char, list all different kind of \n // value it can come up to.\n... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "#include <vector>\n#include <string>\n#include <cctype>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> solve(int i, int j, const string& s) {\n vector<int> res;\n\n // Base case: if the substring is all digits\n if (i > j) return res;\n if (i == j) {\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string e) \n {\n vector<int>results;\n if(e.size()==0)return results;\n if(e.size()==1)\n {\n results.push_back(e[0]-'0');\n return results;\n }\n if(e.size()==2 && isdigit(e[0]))... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n vector<int>ans;\n if(expression.size()==1) {\n ans.push_back(expression[0]-'0');\n\n return ans;\n \n \n }\n bool flag = true;\n for(int i=0;i<ex... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "\nclass Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n vector<int> result;\n bool isNumber = true;\n int num = 0;\n for (char c : expression) {\n if (isdigit(c)) {\n num = num * 10 + (c - '0');\n } else {\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "\nclass Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n vector<int> result;\n bool isNumber = true;\n int num = 0;\n for (char c : expression) {\n if (isdigit(c)) {\n num = num * 10 + (c - '0');\n } else {\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string input) {\n vector<int> result;\n int size = input.size();\n for (int i = 0; i < size; i++) {\n char cur = input[i];\n if (cur == '+' || cur == '-' || cur == '*') {\n vector<int> res... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "\nclass Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n vector<int> result;\n bool isNumber = true;\n int num = 0;\n for (char c : expression) {\n if (isdigit(c)) {\n num = num * 10 + (c - '0');\n } else {\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "\nclass Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n vector<int> result;\n bool isNumber = true;\n int num = 0;\n for (char c : expression) {\n if (isdigit(c)) {\n num = num * 10 + (c - '0');\n } else {\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n int perform(int x,int y,char op){\n\n if(op== '+') return x+y;\n if(op=='-') return x-y;\n if(op == '*') return x*y;\n if(op == '/') return x/y;\n return 0;\n }\n vector<int> diffWaysToCompute(string exp) {\n \n\n vector<... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n // function to get the result of the operation\n int perform(int x, int y, char op) {\n if(op == '+') return x + y;\n if(op == '-') return x - y;\n if(op == '*') return x * y;\n return 0;\n }\n \n vector<int> diffWaysToCompute(string ex... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\n\npublic:\n\n vector<int> diffWaysToCompute(string expression) {\n\n vector<int> results;\n\n // Base case: if the string is empty, return an empty list\n\n if (expression.length() == 0) return results;\n\n // Base case: if the string is a single character, ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n vector<int> results;\n\n // Base case: if the string is empty, return an empty list\n if (expression.length() == 0) return results;\n\n // Base case: if the string is a single character, treat it... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n int perform(int x, int y, char op) {\n if(op == '+') return x + y;\n if(op == '-') return x - y;\n if(op == '*') return x * y;\n return 0;\n }\n \n vector<int> diffWaysToCompute(string exp) {\n \n vector<int> results;\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n \n int perform(int x, int y, char op) {\n if(op == '+') return x + y;\n if(op == '-') return x - y;\n if(op == '*') return x * y;\n return 0;\n }\n \n vector<int>helper(string exp){\n vector<int>ans;\n if(exp.size()==1)\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 1 | {
"code": "class Solution {\npublic:\n // function to get the result of the operation\n int perform(int x, int y, char op) {\n if(op == '+') return x + y;\n if(op == '-') return x - y;\n if(op == '*') return x * y;\n return 0;\n }\n \n vector<int> diffWaysToCompute(string ex... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 2 | {
"code": "class Solution {\npublic:\n // function to get the result of the operation\n int perform(int x, int y, char op) {\n if(op == '+') return x + y;\n if(op == '-') return x - y;\n if(op == '*') return x * y;\n return 0;\n }\n \n vector<int> diffWaysToCompute(string ex... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 2 | {
"code": "class Solution {\npublic:\n int perform(int x,int y,char op){\n if(op=='+') return x+y ;\n if(op=='-') return x-y ;\n if(op=='*') return x*y;\n return 0;\n }\n vector<int> diffWaysToCompute(string expression) {\n vector<int>ans;\n bool isNum = true;\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 2 | {
"code": "class Solution {\npublic:\n vector<int> helper(string &s, int i, int j) {\n if (i > j) return {}; \n \n string num = s.substr(i, j - i + 1);\n if (num.find_first_not_of(\"0123456789\") == string::npos) {\n return {stoi(num)}; \n }\n\n vector<int> an... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 2 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n vector<int> ans;\n for (int i = 0; i < expression.size(); i++) {\n char curr = expression[i];\n if (curr == '*' || curr == '+' || curr == '-') {\n vector<int> left, right;\... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 2 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string exp) {\n bool flag = true;\n vector<int>res;\n for(int i=0;i<exp.length();i++){\n if(!isdigit(exp[i])){\n flag = false;\n vector<int>left = diffWaysToCompute(exp.substr(0,i));\n... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 2 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n vector<int> result;\n\n for(int i=0;i<expression.length();i++){\n char ch = expression[i];\n\n if(ch=='*' || ch=='+' || ch=='-'){\n vector <int> left = diffWaysToCompute(ex... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string exp) {\n vector<int>ans;\n int flag=0;\n for(int i=0;i<exp.size();i++){\n if(exp[i]=='-' || exp[i]=='*' || exp[i]=='+'){\n flag=1;\n vector<int>x=diffWaysToCompute(exp.substr(0,... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "class Solution {\npublic:\n \n vector<int> diffWaysToCompute(string input) {\n vector<int> ans;\n\n bool pureNum=true;\n\n for (int i=0; i<input.length(); i++) \n \n if (input[i]<'0' || input[i]>'9') {\n pureNum=false;\n \n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "class Solution {\npublic:\n int evaluate(int a, int b, char op) {\n switch (op) {\n case '+': return a + b;\n case '-': return a - b;\n case '*': return a * b;\n case '/': return a / b; // Integer division\n default: return 0;\n }\n}\n vector<int> diffWaysToC... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "#define ll long long\nclass Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) \n {\n vector<int>ans;\n ll sz = expression.size();\n\n for(int i=0;i<sz;i++)\n {\n if(expression[i]=='+' ||expression[i]=='-'||expression[i]=='*')\n {\... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n vector<int> result;\n for (int i = 0; i < expression.size(); i++) {\n if (expression[i] == '+' || expression[i] == '-' || expression[i] == '*') {\n string left = expression.substr(0, ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.