id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n int getSum(vector<int>v){\n\n int sum =0;\n for(auto i : v) sum+=i;\n return sum;\n }\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n\n int m = rolls.size();\n int msum=0;\n msum = getSum(rolls);\n\n int ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int m = rolls.size();\n int sum = 0;\n int val = mean*(n+m);\n\n for(auto i : rolls){\n sum += i;\n }\n\n val = val - sum;\n vector<int> missingRolls;... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int remain = (n+rolls.size())*mean;\n for(auto i:rolls)\n remain -= i;\n if(remain > 6*n || remain < n)\n return {};\n vector<int> res;\n int val = remai... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int remain = (n+rolls.size())*mean;\n for(auto i:rolls)\n remain -= i;\n if(remain > 6*n || remain < n)\n return {};\n vector<int> res;\n int val = remai... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\n public:\n vector<int> missingRolls(vector<int> &rolls, int mean, int n) {\n int m = rolls.size(), totalSum = mean * (m + n);\n int sumOfM = 0;\n for (int roll : rolls) sumOfM += roll;\n\n int sumOfN = totalSum - sumOfM;\n i... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "#include <numeric>\nclass Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n vector<int> ans;\n int m = rolls.size();\n int sum = std::accumulate(rolls.begin(), rolls.end(), 0);\n int sum_of_n = (m+n)*mean - sum;\n if ( sum_of_n<n |... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int remain = (n+rolls.size())*mean;\n for(auto i:rolls)\n remain -= i;\n if(remain > 6*n || remain < n)\n return {};\n vector<int> res;\n int val = remai... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int remain = (n+rolls.size())*mean;\n for(auto i:rolls)\n remain -= i;\n if(remain > 6*n || remain < n)\n return {};\n vector<int> res;\n int val = remai... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "// #pragma GCC optimize(\"O3\", \"unroll-loops\")\n\n// auto init = []() {\n// ios::sync_with_stdio(0);\n// cin.tie(0);\n// cout.tie(0);\n// return 'c';\n// }();\n\nclass Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int m = rolls.size();\... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n // METHOD 1\n // long long sum=0;\n // for(int element : rolls){\n // sum+=element;\n // }\n // int unKnown=mean*(rolls.size()+n)-sum;\n // if(n*6<unKnown ||... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n\n int total = 0;\n int m = rolls.size();\n for (int i = 0; i < m; i++) {\n total += rolls[i];\n }\n total = (n + m) * mean - total;\n if (total > n * 6 || to... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n\n int total = 0;\n int m = rolls.size();\n for (int i = 0; i < m; i++) {\n total += rolls[i];\n }\n total = (n + m) * mean - total;\n if (total > n * 6 || to... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int m = rolls.size();\n int presentSum = reduce(rolls.begin(), rolls.end(), 0);\n int sum = mean * (n + m);\n int missingSum = sum - presentSum;\n int missingAvg = missingSum ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int m = rolls.size();\n int presentSum = 0;\n int sum = mean * (n + m);\n for(int i = 0; i < m; i++){\n presentSum += rolls[i];\n }\n int missingSum = sum - ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\n private:\n //static vector<int> emptyVec;\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) \n {\n std::ios_base::sync_with_stdio(false);\n cin.tie(0); \n int sum = accumulate(rolls.cbegin(),rolls.cend(), 0);\n int rollsCount ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int sumLength = n + (int)rolls.size();\n int total = sumLength * mean;\n for(int roll:rolls){\n total -= roll;\n }\n rolls.resize(n);\n if(total < n)return v... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int num = mean*(rolls.size()+n)-int(accumulate(rolls.begin(),rolls.end(),0));\n int rmin = num%n;\n rolls.clear();\n rolls.resize(n,num/n);\n for(int i=0;rmin>0;i++){\n ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int num = mean*(rolls.size()+n)-int(accumulate(rolls.begin(),rolls.end(),0));\n int rmin = num%n;\n rolls.clear();\n rolls.resize(n,num/n);\n for(int i=0;rmin>0;i++){\n ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int sum = 0, m = rolls.size();\n for(int i=0;i<rolls.size();i++)\n sum += rolls[i];\n int sumOfNValues = (mean * (n + m)) - sum;\n\n if(sumOfNValues > 6 * n || sumOfNValue... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int m = rolls.size();\n int sum = mean * (m + n);\n\n for (int roll : rolls) {\n sum -= roll;\n }\n\n // float remain_average = (float)sum / n;\n int small_n... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int roll_sum=accumulate(rolls.begin(), rolls.end(), 0);\n int missing_sum=mean*(n+rolls.size())-roll_sum;\n int missing_avg=missing_sum/n;\n int missing_remain=missing_sum%n;\n ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int m = rolls.size();\n int k = m+n;\n int total_sum = mean*k;\n int curr_sum = 0;\n\n for(auto e: rolls){\n curr_sum+=e;\n }\n\n int diff = total_sum... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int m = rolls.size();\n int k = m+n;\n int total_sum = mean*k;\n int curr_sum = 0;\n\n for(auto e: rolls){\n curr_sum+=e;\n }\n\n int diff = total_sum... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int m = rolls.size();\n int k = m+n;\n int total_sum = mean*k;\n int curr_sum = 0;\n\n for(auto e: rolls){\n curr_sum+=e;\n }\n\n int diff = total_sum... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int m = rolls.size(), sum = 0;\n for(int roll: rolls)\n sum += roll;\n int rem = mean*(m+n) - sum;\n if(rem > n*6 || rem < n)\n return {};\n int m2 = rem... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int mem = 0;\n\n for(int i=0;i<rolls.size();i++){\n mem += mean - rolls[i];\n }\n\n mem += mean*n;\n\n if(mem < n || mem > 6*n)\n return {};\n ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int m=rolls.size();\n int sum=0;\n for(auto it:rolls){\n sum+=it;\n }\n int total_sum=mean*(m+n);\n total_sum-=sum;\n if(total_sum<n){\n re... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n int calcSum(vector<int> arr)\n {\n int ans = 0;\n for(int i = 0; i < arr.size(); i++) ans += arr[i];\n return ans;\n }\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) \n {\n vector<int> remain(n, 1);\n\n int total... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int nSum = getSumN(mean, n, rolls);\n\n return findUniqueCombination(n, nSum);\n }\n\n vector<int> findUniqueCombination(int k, int targetSum) {\n vector<int> result(k, 1); \n ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int mem = 0;\n\n for(int i=0;i<rolls.size();i++){\n mem += mean - rolls[i];\n }\n\n mem += mean*n;\n\n if(mem <=0 || mem / n == 0 || mem / n > 6 || (mem / n == ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int mem = 0;\n\n for(int i=0;i<rolls.size();i++){\n mem += mean - rolls[i];\n }\n\n mem += mean*n;\n\n if(mem <=0 || mem / n == 0 || mem / n > 6 || (mem / n == ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int m = rolls.size();\n int sum = (n + m) * mean - accumulate(rolls.begin(), rolls.end(), 0);\n\n if (sum < n || sum > 6 * n)\n {\n return vector<int>();\n }\n\n ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "#include <ios>\n#include <vector>\nusing namespace std;\n\nclass Solution {\n public:\n vector<int> missingRolls(vector<int> const &nums, int mean, int const m) {\n int const n = size(nums); // [1, 1e5]\n mean *= n + m;\n int sum = reduce(nums.begin(), end(nums)) + m;\n if... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n bool findRolls(int sum, int n, vector<int>& rolls, vector<int>& result, int index) {\n if (n == 0) {\n return sum == 0;\n }\n if (sum < n || sum > 6 * n) {\n return false;\n }\n\n for (int i = 1; i <= 6; ++i) {\n ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\nprivate:\n vector<int> result;\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int m = rolls.size();\n int totalSum = mean*(m+n);\n int currentSum = 0;\n int requiredSum = 0;\n for(int i=0; i<m; i++) currentSum += rolls... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "#include <bits/stdc++.h>\nclass Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n // int mSum = accumulate(rolls.begin(),rolls.end(),0);\n int mSum = 0;\n for(int i : rolls) mSum += i;\n int total = rolls.size()+n;\n\n \n in... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "#include <bits/stdc++.h>\nclass Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int mSum = accumulate(rolls.begin(),rolls.end(),0);\n \n int total = rolls.size()+n;\n\n \n int miss = (mean*total) - mSum;\n\n if(!((n*1>miss... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "#include <bits/stdc++.h>\nclass Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int mSum = accumulate(rolls.begin(),rolls.end(),0);\n int total = rolls.size()+n;\n\n \n int miss = (mean*total) - mSum;\n\n if(!((n*1>miss)||(n*6<mi... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "#include <bits/stdc++.h>\nclass Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int mSum = accumulate(rolls.begin(),rolls.end(),0);\n int total = rolls.size()+n;\n\n \n int miss = (mean*total) - mSum;\n\n if(!((n*1>miss)||(n*6<mi... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int sumN= accumulate(rolls.begin(),rolls.end(),0);\n int sumM=(mean*(rolls.size()+n))-sumN;\n if(sumM<0)\n return {};\n int q=sumM/n, rem=sumM%n;\n if(q>6 || q<1)\n return {};... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int rest = mean * (rolls.size() + n) - accumulate(rolls.begin(), rolls.end(), 0);\n if (rest < n or rest > 6 * n) {\n return {};\n }\n \n int val2 = rest / n;\n ... |
2,155 | <p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> missingRolls(vector<int>& rolls, int mean, int n) {\n int m = rolls.size();\n int total_sum = mean * (m+n);\n int curr_sum = accumulate(rolls.begin(), rolls.end(), 0);\n int rem = total_sum - curr_sum;\n if (rem < n){\n ... |
2,161 | <p>You are given a stream of <strong>records</strong> about a particular stock. Each record contains a <strong>timestamp</strong> and the corresponding <strong>price</strong> of the stock at that timestamp.</p>
<p>Unfortunately due to the volatile nature of the stock market, the records do not come in order. Even wors... | 0 | {
"code": "// problem structure: save current, max, min, but update operation will change them all\n// Solution1: indexpriorityqueue to maintain the max heap and min heap\n// update: O(logN)\n// current/max/min: O(1)\n// Space: O(2N)\n\n// Solution2: hashmap + 2 priority queue, use map to track valid price and lazy d... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string &num) {\n while(!empty(num) and (num.back() - '0') % 2 == 0){\n num.pop_back();\n }\n return move(num);\n }\n};",
"memory": "14000"
} |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string &num) {\n while(!empty(num) && (num.back()-'0')%2 == 0) {\n num.pop_back();\n }\n return move(num);\n }\n};",
"memory": "14100"
} |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string &num) {\n while(!empty(num) and (num.back() - '0') % 2 == 0){\n num.pop_back();\n }\n return move(num);\n }\n};",
"memory": "14200"
} |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string &num) {\n while(!empty(num) and (num.back() - '0') % 2 == 0){\n num.pop_back();\n }\n return move(num);\n }\n};",
"memory": "14300"
} |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string &num) {\n while(!empty(num) and (num.back() - '0') % 2 == 0){\n num.pop_back();\n }\n return num;\n }\n};",
"memory": "15000"
} |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n while(!empty(num) and (num.back() - '0') % 2 == 0){\n num.pop_back();\n }\n return move(num);\n }\n};",
"memory": "15100"
} |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int cnt=0;\n for(int i=num.length()-1;i>=0;i--){\n int c=(int)num[i];\n if(c&1){\n break;\n }\n else{\n cnt++;\n }\n }\n\n ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int n=num.length();\n for(int s=n-1;s>=0;s--){\n // check from right to left\n int val=num[s]-'0'; \n // change string into digit\n if(val%2==0)\n // check even odd\n num.pop_ba... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n while (!num.empty()) {\n if ((num.back() - '0') % 2 == 0) {\n num.pop_back();\n } else\n break;\n }\n return num;\n }\n};",
"memory": "15300"
} |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int n=num.length();\n int i=n-1;\n while(i>=0){\n if((num[i]-'0')%2!=0){\n return num;\n }else{\n num.pop_back();\n i--;\n }\n }\n... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int n=num.length()-1;\n int i=0;\n \n while(n>=0){\n if(num[n]%2!=0){\n num.erase(n+1,num.length());\n i++;\n break;\n }\n n--;\n ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int n=num.size();\n for(int i=n-1;i>=0;i--){\n int number=num[i]-'0';\n if(number%2!=0) break;\n else{\n num.erase(i);\n }\n }\n return num;\n }\n... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int n = num.length();\n if(num.back() % 2 == 1) return num;\n int i = n-1;\n while(i>=0){\n int m = num[i];\n if(m%2 == 1) return num.substr(0, i+1);\n i--;\n }\n ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int n = num.size() - 1;\n if(num[n]-0 & 1){\n return num;\n }\n string ans = \"\";\n int ind = 0;\n for(int i=n; i>=0; i--){\n if(num[i]-0 & 1){\n ans = num.... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int i = num.size()-1;\n while(i>=0){\n if(num[i]%2 != 0 && i==num.size()-1){\n return num;\n }\n else if(num[i]%2 != 0){\n return num.erase(i+1,num.size()-1);\... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int n=num.length();\n if(num[n-1] %2==1){\n return num;\n }\n \n else{\n for(int i = n - 1; i >= 0; --i){\n if((num[i])%2==1){\n return num.subst... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int n=num.size();\n int i=0,j=n-1;\n int maxodd=0;\n string sub=\"\";\n if(num[j]%2!=0){\n return num;\n }\n while(j>0){\n while(j>0 && num[j]%2==0){\n ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n // string maxOddSubString = \"\";\n // for(int i = 0; i< num.size(); i++) {\n // string subString = \"\";\n // for(int j = i; j<num.size(); j++) {\n // subString += num[j];\n // ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int n=num.size();\n for(int i=n-1;i>=0;i--){\n if((num[i]-'0')%2==1){\n return num.substr(0,i+1);\n }\n }\n return \"\";\n }\n};",
"memory": "16300"
} |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n \n for (int i = num.size() - 1; i >= 0; --i) {\n \n if ((num[i] - '0') % 2 != 0) {\n \n return num.substr(0, i + 1);\n }\n }\n \n return \"\... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 0 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int n = num.length(), i = 0;\n // if (n == 0)\n // return \"\";\n for (i = n - 1; i >= 0; i--) {\n if (num[i] % 2 == 0 && i == 0)\n return \"\";\n else if (num[i] % 2 ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 1 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n string maxi=\"\";\n int n;\n for(int i= num.size()-1;i>=0;i--)\n {\n if((num[i]-0)&1)\n {\n maxi = num.substr(0,i+1);\n break;\n }\n }\n \n return... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 1 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int i=num.length()-1;\n for(i;i>=0;i--){\n if(num[i]%2!=0){\n break;\n }\n }\n return num.substr(0,i+1);\n }\n};",
"memory": "16500"
} |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 2 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int idx = num.length()-1;\n while(idx>=0 && ((num[idx]-'0')&1)==0 )\n {\n idx--;\n }\n return num.substr(0,idx+1);\n }\n};",
"memory": "16600"
} |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 2 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int n = num.length(), i = 0;\n if (n == 0)\n return \"\";\n for (i = n - 1; i >= 0; i--) {\n if (num[i] % 2 == 0 && i == 0)\n return \"\";\n else if (num[i] % 2 != 0)\... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string s) {\n string result = \"\";\n \n for (int i = s.length() - 1; i >= 0; i--) {\n if (isdigit(s[i])) {\n int digit = s[i] - '0'; \n if (digit % 2 != 0) { \n result = s.substr(0, i + 1); \n ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "#include<bits/stdc++.h>\n#include <cstdlib>\nclass Solution {\npublic:\n string largestOddNumber(string s) {\n\n if((s[s.size()-1])%2!=0)\n return s;\n string ans;\n int q=0,d=0;\n for(int i=s.size()-1;i>=0;i--){\n if((s[i]-'0')%2==0){\n d++;... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int n=num.length();\n string res=num;\n int ans=-1;\n if(num[n-1]%2!=0) return num;\n for(int i=n-1; i>=0; i--){\n if(num[i]%2==0 ){\n res.erase(i,1);\n }\n else if(num[i]%2!... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "#include<bits/stdc++.h>\n#include <cstdlib>\nclass Solution {\npublic:\n string largestOddNumber(string s) {\n\n if((s[s.size()-1])%2!=0)\n return s;\n string ans;\n for(int i=s.size()-1;i>=0;i--){\n if((s[i]-'0')%2==0)\n continue;\n else{\... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n string s=\"\";\n unordered_map<char,int>mp;\n mp['1']=0;\n mp['3']=0;\n mp['5']=0;\n mp['7']=0;\n mp['9']=0;\n for(int i=num.size()-1;i>=0;i--){\n if(mp.find(num[i])!=mp... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n unordered_set<char> oddDigits = {'1', '3', '5', '7', '9'};\n \n // Start iterating from the rightmost character of the string\n for (int i = num.length() - 1; i >= 0; i--) {\n // If the current ch... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n string ans = \"\";\n int n = num.size();\n int ind = -1;\n if(num[n-1]%2)return num;\n for(int i=n-1; i>=0; i--){\n if(num[i]%2==1){\n ind = i;\n break;\n ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n string ans = \"\";\n if((num[num.size() -1] - '0') % 2) ans = num;\n int oddIdx = -1;\n for(int i = 0; i < num.size(); i++) {\n if ((num[i] - '0') % 2) oddIdx = i;\n }\n string ans2 =... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n string ans;\n if((num[num.length()-1]-'0')%2==1){\n return num;\n }\n int an =-1;\n for(int i =num.length()-1; i>=0; i--){\n if((num[i]-'0')%2==1){\n \n an... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n //int val=stoi(num);\n int n=num.size();\n string ans; string ans1;\n if(num[n-1]%2!=0) return num;\n int pos; bool odd=true;\n for(int i=0;i<n;i++){\n if(num[i]%2==0){\n ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int length = num.length();\n string ans = \"\";\n string temp = \"\";\n char edge = num[length - 1];\n if((int) edge % 2 != 0){\n return num;\n }\n for(int i=0;i<length;i++){\n... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "#include<bits/stdc++.h>\nclass Solution {\npublic:\n string largestOddNumber(string str) {\n int n = str.length();\n if(n==1 && (str[n-1]%2 != 0))return str;\n else if(n==1) return \"\";\n\n string ans = \"\";\n // int flag = 1;\n\n for(int i=n-1;i>=0;i--){\n ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int index = 1e9;\n int n = num.size();\n string temp = \"\";\n for (int i = n - 1; i >= 0; i--) {\n temp += num[i];\n // cout << temp << ' '; \n int num = stoi(temp);\n ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n for(int i = num.size()-1;i>=0;i--){\n string str(1,num[i]);\n int numi = stoi(str);\n if(numi%2!=0)\n return num.substr(0,i+1);\n }\n return \"\";\n }\n};",
"memory":... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "#include<bits/stdc++.h>\nclass Solution {\npublic:\n string largestOddNumber(string s) {\n // int j=num.size()-1;\n // long long int n=INT_MIN;\n // while(j>=0){\n // string sub=num.substr(0,j+1);\n // long long int val=stoll(sub);\n // if(val%2!=0) ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "#include<bits/stdc++.h>\nclass Solution {\npublic:\n string largestOddNumber(string str) {\n int n = str.length();\n if(n==1 && (str[n-1]%2 != 0))return str;\n else if(n==1) return \"\";\n\n string ans = \"\";\n // int flag = 1;\n\n for(int i=n-1;i>=0;i--){\n ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "#include<bits/stdc++.h>\nclass Solution {\npublic:\n string largestOddNumber(string str) {\n ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n int n = str.length();\n // if(n==1 && (str[n-1]%2 != 0))return str;\n // else if(n==1) return \"\";\n\n string ans = \"\";\n\n... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n \n string ans;\n int last_index = -1;\n int n = num.length();\n\n for(int i= n-1; i>= 0;i--){\n if((num[i] - '0') % 2 != 0){\n last_index = i;\n break;\n ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n int length=num.size()-1;\n int value=-1;\n for(int i=length;i>=0;i--){\n if(int(num[i])%2!=0){\n value=i;\n break;\n }\n }\n if (value == -1) {\n ... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n\n\n int ans = -1;\n int n = num.size();\n string s = \"\";\n\n for(int i=0;i<n;i++){\n\n if (num[i] % 2==1){\n ans = i;\n }\n \n }\n\n for(int i=0... |
2,032 | <p>You are given a string <code>num</code>, representing a large integer. Return <em>the <strong>largest-valued odd</strong> integer (as a string) that is a <strong>non-empty substring</strong> of </em><code>num</code><em>, or an empty string </em><code>""</code><em> if no odd integer exists</em>.</p>
<p>A <... | 3 | {
"code": "class Solution {\npublic:\n string largestOddNumber(string num) {\n string str=\"\";\n int i;\n for( i=num.length()-1;i>=0;i--)\n {\n int odd=(int)num[i]-'48';\n if(odd%2!=0)\n {\n int j=0;\n while(j<=i)\n {\n ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "#pragma GCC optimize (\"Ofast\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native\")\nstruct UnionFind {\n vector<int> parent, rank;\n vector<char> isSubIsland;\n explicit UnionFind(int n) : parent(vector<int>(n)), rank(vector<int>(n, 1)), isSubIsland(vector<char>(n, ... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "#pragma GCC optimize (\"Ofast\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native\")\nstruct UnionFind {\n vector<int> parent, rank, isSubIsland;\n explicit UnionFind(int n) : parent(vector<int>(n)), rank(vector<int>(n, 1)), isSubIsland(vector<int>(n, true)) {\n i... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n bool check(vector<vector<int>>& grid1,vector<vector<int>>& grid2,int i,int j){\n int r[4]={-1,0,0,1};\n int c[4]={0,-1,1,0};\n bool b=1;\n // grid2[i][j]=0;\n // grid2[i][j]=0;\n for(int ind=0;ind<4;ind++){\n int nr=i+r[ind... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "#pragma GCC optimize(\"O3\", \"unroll-loops\")\n\nstatic auto speedup = [](){\n ios_base::sync_with_stdio(false);\n cout.tie(NULL);\n cin.tie(NULL);\n return NULL;\n}();\n\nconstexpr int cyMask = 511 << 9, cyStep = 1 << 9;\n\nclass Solution {\npublic:\n int countSubIslands(vector<vector<int>... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n int n = 0;\n int m = 0;\n\n int countSubIslands(vector<vector<int>>& grid1, vector<vector<int>>& grid2) {\n n = grid1.size();\n m = grid1[0].size();\n\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if (gr... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n int markIslands(vector<vector<int>>& grid,\n const vector<vector<int>>& overlay) {\n const int ROWS = grid.size();\n const int COLS = grid[0].size();\n\n vector<pair<int16_t, int16_t>> st; // {r,c}\n\n const auto test = [&](const... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n int markIslands(vector<vector<int>>& grid,\n const vector<vector<int>>& overlay) {\n const int ROWS = grid.size();\n const int COLS = grid[0].size();\n\n vector<pair<int16_t, int16_t>> st; // {r,c}\n\n const auto test = [&](const... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n int markIslands(vector<vector<int>>& grid,\n const vector<vector<int>>& overlay) {\n const int ROWS = grid.size();\n const int COLS = grid[0].size();\n\n vector<pair<int16_t, int16_t>> st; // {r,c}\n\n const auto test = [&](const... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n int markIslands(vector<vector<int>>& grid,\n const vector<vector<int>>& overlay) {\n const int ROWS = grid.size();\n const int COLS = grid[0].size();\n\n vector<pair<int16_t, int16_t>> st; // {r,c}\n\n const auto test = [&](const... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n int markIslands(vector<vector<int>>& grid,\n const vector<vector<int>>& overlay) {\n const int ROWS = grid.size();\n const int COLS = grid[0].size();\n\n vector<int> st; // (r << 10) + c\n\n const auto test = [&](const int r, con... |
2,035 | <p>You are given two <code>m x n</code> binary matrices <code>grid1</code> and <code>grid2</code> containing only <code>0</code>'s (representing water) and <code>1</code>'s (representing land). An <strong>island</strong> is a group of <code>1</code>'s connected <strong>4-directionally</strong> (horizontal o... | 0 | {
"code": "class Solution {\npublic:\n int markIslands(vector<vector<int>>& grid,\n const vector<vector<int>>& overlay) {\n const int ROWS = grid.size();\n const int COLS = grid[0].size();\n\n vector<pair<int16_t, int16_t>> st; // {r,c}\n\n const auto test = [&](const... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.