id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
395 | <p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p>
<p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n return helper(s, k, 0, s.length());\n }\nprivate:\n int helper(string s, int k, int start, int end) {\n if (end - start < k) return 0;\n int count[26] = {0};\n for (int i = start; i < end; i++) {\n ... |
395 | <p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p>
<p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n return longestSubstringUtil(s, k, 0, s.length());\n }\n \nprivate:\n int longestSubstringUtil(string s, int k, int start, int end) {\n if (end - start < k) return 0;\n \n int count[26] = {0};\n ... |
395 | <p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest substring of</em> <code>s</code> <em>such that the frequency of each character in this substring is greater than or equal to</em> <code>k</code>.</p>
<p data-pm-slice="1 1 []">if no such substring exists, return 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n return longestSubstringUtil(s, k, 0, s.length());\n }\n\n int longestSubstringUtil(string s, int k, int start, int end) {\n if (end - start < k) return 0;\n\n int count[26] = {0};\n for (int i = start... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 0 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n vector<int> ans;\n const int n = nums.size();\n //vector<int> dp(n, 1); //longest sequence ending at index i \n int dp[n];\n std::fill_n(dp... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 0 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n vector<int> res;\n \n int n = nums.size();\n if(n == 0){\n return res;\n }\n \n int count[n];\n int pre[n];\n \n sort(nums.begin(), nums.... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 0 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n vector<int> dp(nums.size(), 1);\n sort(nums.begin(), nums.end());\n int indMax = 0;\n int maxVal = 0;\n for (int i = 1; i != nums.size(); ++i)\n {\n for (int j = 0; ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 0 | {
"code": "class Solution {\npublic:\n \n vector<int> largestDivisibleSubset(vector<int>& nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n vector<int> dp(n,1);\n vector<int> hash(n);\n for(int i=0;i<n;i++){\n hash[i]=i;\n for(int j=0;j<i;j+... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 0 | {
"code": "class Solution {\npublic:\n void solve(vector<int>& nums,int idx1,int idx2){\n\n\n }\n\n vector<int> largestDivisibleSubset(vector<int>& arr) {\n \n sort(arr.begin(),arr.end());\n\n vector<int> dp(arr.size(),1);\n vector<int> hash(arr.size(),0);\n int maxi = 1;\n... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 0 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n int n=nums.size();\n int maxi=1;\n int LastIndex=0;\n vector<int> dp(n,1), hash(n);\n sort(nums.begin(),nums.end());\n for(int i=0;i<n;i++)\n {\n hash[i]=i;\n... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 0 | {
"code": "class Solution {\npublic:\n \n vector<int> largestDivisibleSubset(vector<int>& nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n vector<int> dp(n,1);\n vector<int> hash(n);\n for(int i=0;i<n;i++){\n hash[i]=i;\n for(int j=0;j<i;j+... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 1 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n vector<int>dp(n,1);\n vector<int>in(n);\n int ind=0;\n for(int i=0;i<n;i++)in[i]=i;\n for(int i=1;i<n;i++){\n ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 1 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& arr) {\n sort(arr.begin(),arr.end());\n int n=arr.size();\n vector<int>dp(n,1);\n vector<int>hash(n);\n int max=INT_MIN;\n int d=0;\n for(int i=0;i<n;i++ ){\n hash[i]=i... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 2 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n int n = nums.size();\n if (n == 0) return {};\n \n sort(nums.begin(), nums.end());\n vector<int> dp(n, 1), hash(n, 0);\n \n \n for (int i = 0; i < n; ++i) {\n ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 2 | {
"code": "/*\nclass Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n = nums.size();\n vector<int> subset_length(n,0);\n vector<int> previous_index(n,0);\n subset_length[0] = 1;\n previous_index[0] = -1;... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie();\n\n int n = nums.size();\n sort(begin(nums), end(nums));\n int maxi = 1, lastind = 0;\n vector<int> dp(n, 1), h... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie();\n\n int n = nums.size();\n sort(begin(nums), end(nums));\n int maxi = 1, lastind = 0;\n vector<int> dp(n, 1), h... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n if(nums.size()==0){\n return nums;\n }\n sort(nums.begin(),nums.end());\n int flag=1;\n if(nums[0]==1){\n flag=0;\n }\n else{\n nums.pus... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n void findSeq(int s, vector<int> nums, int len, int *dp, vector<int> &v){\n if(len==0||s==0) return;\n for(int i = s-1; i>=0; i--){\n if(nums[s]%nums[i]==0&&dp[i]==len-1){\n v.push_back(nums[i]);\n findSeq(i,nums,len-1,dp,... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n vector<int> dp(2502, 1);\n int ans = 0;\n // dp[0]=1;\n // ans = max(ans, dp[0]);\n vector<int> prev(1002);\n\n for (int i=0; i<1002; i++) prev[i]=i;\n int maxind = 0;\n... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n void findSeq(int s, vector<int> nums, int len, int *dp, vector<int> &v){\n if(len==0||s==0) return;\n for(int i = s-1; i>=0; i--){\n if(nums[s]%nums[i]==0&&dp[i]==len-1){\n v.push_back(nums[i]);\n findSeq(i,nums,len-1,dp,... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n void findSeq(int s, vector<int> nums, int len, int *dp, vector<int> &v){\n if(len==0||s==0) return;\n for(int i = s-1; i>=0; i--){\n if(nums[s]%nums[i]==0&&dp[i]==len-1){\n v.push_back(nums[i]);\n findSeq(i,nums,len-1,dp,... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> ans;\n void rec(vector<int> &nums, vector<int> &k, int ind,int prev, vector<int> &dp){\n if(ind==nums.size()){\n if(k.size()>ans.size()) ans = k;\n return ;\n }\n rec(nums, k, ind+1, prev, dp);\n if(prev==-1 || ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n if(nums.size()==0){\n return {};\n }\n if(nums.size()==1){\n return nums;\n }\n \n sort(nums.begin(),nums.end());\n vector<vector<int>>dp(nums.size... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "\nclass Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n vector<vector<int>> memo(nums.size(), vector<int>());\n vector<int> largestSubset{-1, -1, 0};\n for(int i = nums.size() - 1; i >= 0; i--) {\n f... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n vector<int> dp[n];\n\n for (int i=n-1; i>=0; i--){\n dp[i].push_back(nums[i]);\n vector<int> store;\n ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\nvector<int> solve(vector<int>& nums ,int index,vector<vector<int>> &dp){\n if(index==nums.size()) return {};\n if(!dp[index].empty()) return dp[index];\n vector<int> ans{nums[index]};\n vector<int> temp;\n for(int j=index+1;j<nums.size();j++){\n if (nums[j] ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n std::vector<int> largestDivisibleSubset(std::vector<int>& nums) {\n std::sort(nums.begin(), nums.end());\n std::vector<std::vector<int> > dp(nums.size());\n\n dp[0].push_back(1);\n dp[0].push_back(0);\n\n int maxSetSize = 1;\n int max... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n vector<vector<int>> dp(nums.size());\n // for(int i =0; i<n; i++){\n // dp[i] = {nums[i]};\n // }\n dp[n-1] ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n vector<int>cont[n+1];\n vector<int>ans;\n int maxSize = 0, maxSizeKey = 0;\n for(int i=0; i<n; i++) {\n for(... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n\n pair<size_t, size_t> out;\n vector<vector<int>> dp(nums.size());\n for (size_t i = 0; i < nums.size(); i++) {\n size_t max_j = i;\n ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n vector<vector<int>> dp(nums.size());\n int n = nums.size();\n size_t ans = 0;\n for (int i = 0; i < n; ++i) {\n size_t len = 0;\n ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n \n int n = nums.size(), id, mx=0, tx=1;\n \n vector<int> res;\n \n int dp[1001];\n memset(dp, 1, sizeof(dp));\n \n vector<vector<int>> s(n);\n \n ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n void using_rec(vector<int>& nums,vector<int>&ans,vector<int>temp1,int temp,int prev){\n if(temp == nums.size()){\n if(temp1.size() > ans.size()){ans = temp1;}\n return;\n }\n if(prev == -1 || (nums[temp]%prev == 0)){\n tem... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n vector<int> count(nums.size(),1);\n map<int,int> mp;\n int last=0,mx=INT_MIN;\n for(int i=0;i<nums.size();i++)\n {\n mp[i]=i;\n ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n vector<int>dp(n+1,1);\n map<int,int>mp;\n int lastInd=0;\n int maxi=0;\n for(int i=0;i<n;i++){\n mp[i]=i... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "// void sort(vector<int>& nums) {\n// for(int i = 0; i < nums.size() - 1; ++i) {\n// for(int j = i + 1; j < nums.size(); ++j) {\n// if(nums[j] < nums[i]) {\n// int temp = nums[j];\n// nums[j] = nums[i];\n// nums[i] = temp;\n// ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n int size = nums.size();\n sort(nums.begin(), nums.end(), [](const int val1, const int val2)->bool{\n return val1 > val2;\n });\n vector<vector<int>> multChain(size);\n int ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n int n =nums.size();\n vector<vector<int>> dp(n);\n sort(nums.begin(),nums.end()); \n for(int i=0;i<n;i++){\n dp[i].push_back(nums[i]);\n }\n for (int i=1;i<n;i++)... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n int n = nums.size();\n if (!n) return {};\n vector<vector<int>> dp(n);\n sort(nums.begin(), nums.end());\n for (int i = 0; i < n; i++) {\n dp[i].push_back(nums[i]);\n ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n if(nums.size() == 1) {\n return vector<int>({nums[0]});\n } else if(nums.size() == 2) {\n if(nums[1] % nums[0] == 0) {\n retur... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n if(nums.size() ==1)return nums;\n sort(nums.begin(),nums.end());\n vector<pair<int,vector<int>>>dp(nums.size());\n for(int i=0;i<nums.size();i++){\n dp[i].first = 1;\n ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n = nums.size();\n vector<vector<int>> dp(n);\n dp[0].push_back(nums[0]);\n for(int i = 1; i < n; i++){\n vector<int> include;\n ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n int n =nums.size();\n sort(nums.rbegin(), nums.rend());\n vector<int>idx(n,-1);\n vector<int>dp(n,1); \n for(int i=n-1;i>=0;i--){\n for(int j=i+1;j<n;j++){\n if(nu... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n\n void util (vector<int> &nums, int idx, vector<int> ¤t, vector<int> &largest) {\n if (idx == nums.size()) {\n if (largest.size() < current.size()) {\n largest = current;\n }\n return;\n }\n\n util (nu... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n //memo[i] = max(memo[i - 1], # elements with nums[i] modding over all nums[0] to nums[i-1])\n sort(nums.begin(), nums.end());\n vector<vector<int>> memo(nums.size());\n for(int i = 0; i < nu... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n vector<vector<int>> lis(nums.size(), vector<int>(0));\n sort(nums.begin(), nums.end());\n\n for(int i=0; i<nums.size(); i++) {\n for(int j=0; j < i; j++) {\n if (nums[i] % nums[j] == 0 &&... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n int n= nums.size();\n sort(nums.begin(), nums.end());\n vector<vector<int>>dp(n);\n vector<int> ans;\n for(int i=0; i<n; i++){\n int idx=i;\n for(int j=0; j<i; j... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int>res;\n void helper(int ind,vector<int>&nums,vector<int>r)\n {\n if(ind==nums.size())\n {\n if(r.size()>res.size())\n res=r;\n return;\n }\n // not piking\n helper(ind+1,nums,r);\n\n ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n\n vector<vector<int>> subsets;\n int largest_idx = 0;\n int size = 0;\n\n for (int i = 0; i < nums.size(); ++i) {\n vector<int> tmp;\n ... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> comp(vector<int> &a, vector<int> b){\n if(a.size() > b.size()) return a;\n return b;\n }\n // unordered_map<string,vector<int>> dp;\n // vector<int> solve(vector<int> &nums, int i, int prev){\n // if(i==nums.size()) return {};\n //... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\n vector<int> largestDivisibleSubset(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n vector<vector<int>> dp(n);\n\n vector<int> res;\n\n for(int i=0;i<n;++i){\n vector<int> tmp;\n for(int j... |
368 | <p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>
<ul>
<li><code>answer[i] % answer[j] == 0</code>, or</li>
<li><code>answer[j] % answer[i] =... | 3 | {
"code": "class Solution {\npublic:\nint dp[1010][1010];\nint rec(int level,int mini,vector<int>&a)\n{\n if(level<0){return 0;}\n if(dp[level][mini]!=-1){return dp[level][mini];}\n int ans=1;\n for(int i=0;i<level;i++)\n {\n if(a[i]%a[mini]==0||a[mini]%a[i]==0)\n {\n int temp=... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 0 | {
"code": "class Solution {\npublic:\n\n \n unsigned int combinationSum4(vector<int>& nums, int target) {\n\n unsigned int dp[target+1];\n memset(dp,0,sizeof(dp));\n dp[0] = 1;\n\n for(int i=1;i<=target;i++){\n for(auto v:nums){\n if(i-v>=0)\n ... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 1 | {
"code": "class Solution {\npublic:\n int combinationSum4(vector<int>& nums, int target) {\n vector<long long> dp(target+1,0);\n dp[0]=1;\n for(int i=1;i<=target;i++){\n for(int j=0;j<nums.size();j++){\n if(i-nums[j]>=0){\n if(dp[i]+dp[i-nums[j]]>INT... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 1 | {
"code": "class Solution {\npublic:\n vector<int> dp;\n int combinationSum4Helper(vector<int>& nums,int target){\n if(target==0){\n return 1;\n }\n if(target<0){\n return 0;\n }\n if(dp[target]!=-1){\n return dp[target];\n }\n in... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n int combinationSum4(vector<int>& nums, int target) {\n vector<unsigned long long>dp(target+5,0);\n dp[0]=1;\n for(int i=1;i<=target;i++){\n for(int num:nums){\n if(i-num>=0){\n dp[i]=dp[i]+dp[i-num];\n ... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> nums; // Store the input numbers\n vector<int> memo; // Memoization table\n\n // Wrapper function to call the recursive function\n int combinationSum4(vector<int>& nums, int target) {\n this->nums = nums;\... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n int from_end;\n Solution() {\n ios_base :: sync_with_stdio( false );\n cin.tie( nullptr ) , cout.tie( nullptr );\n }\n int fun( int n ,vector< int >&nums , int val ,vector<int> &dp ) {\n if( val <= 0 ) return val == 0;\n if( n == 0 ) retur... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n vector<int> dp;\n int solve(int target,vector<int> &v){\n int n = v.size();\n if(target == 0) return 1;\n if(target < 0) return 0;\n if(dp[target] != -1) return dp[target];\n int ans = 0;\n for(int i=0;i<n;i++){\n ... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n int dp[201][1001];\n int solve(vector<int>& arr, int t,int i){\n if(i >= arr.size() || t < 0) return 0;\n if(t == 0) return 1;\n if(dp[i][t] != -1) return dp[i][t];\n int take = solve(arr,t-arr[i],0);\n int nottake = solve(arr,t,i+1);\n ... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n int n;\n int dp[201][1001];\n int solve(int i,int t,vector<int>&nums){\n if (t == 0) return 1;\n if (i >= n || t < 0) return 0;\n if (dp[i][t] != -1) return dp[i][t];\n int not_take = solve(0,t-nums[i],nums);\n int take = solve(i+1,t,n... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\n int dp[201][1001];\n private:\n int sol(int index,int target,vector<int>& nums){\n // target acheived\n if(target==0) return 1;\n if(index>=nums.size() || target<0) return 0;\n \n if(dp[index][target]!=-1) return dp[index][target];\n i... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n int n;\n int t[1001][201];\n int solve(vector<int>& nums, int target, int idx) {\n if(target == 0)\n return 1;\n \n if(idx >= n || target < 0)\n return 0;\n \n if(t[target][idx] != -1)\n return t[target... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\n int dp[201][1001];\n private:\n int sol(int index,int target,vector<int>& nums){\n // target acheived\n if(target==0) return 1;\n if(index>=nums.size() || target<0) return 0;\n \n if(dp[index][target]!=-1) return dp[index][target];\n \... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n int n;\n int t[1001][201];\n int solve(vector<int>& nums, int target, int idx) {\n if(target == 0)\n return 1;\n \n if(idx >= n || target < 0)\n return 0;\n \n if(t[target][idx] != -1)\n return t[target... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n int combinationSum4(vector<int>& nums, int target) {\n int n=nums.size();\n vector<vector<unsigned int>> dp(n+1, vector<unsigned int> (target+1, 0));\n for(int i=0; i<=n; i++) dp[i][0]=1; \n\n\n for(int j=1; j<=target; j++){\n for(int i=... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n int combinationSum4(vector<int>& nums, int target) {\n int n = nums.size();\n vector<vector<int>>dp(n+1,vector<int>(target+1,-1));\n return Sum(nums,n,target,dp);\n }\n int Sum(vector<int>&nums,int n,int target,vector<vector<int>>&dp)\n {\n ... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n vector<int> table;\n int combinationSum4(vector<int>& nums, int target) {\n table.resize(target+1, -1);\n unordered_set<int> s(nums.begin(), nums.end());\n return dp(target, s);\n }\n\n int dp(int num, unordered_set<int> &s){\n\n int count... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n int combinationSum4(vector<int>& nums, int t) {\n int n=nums.size();\n vector<int> memo(t+1,-1);\n\n function<int(int )> helper=[&](int target)->int{\n //if(target<0) return 0;\n if(target==0) return 1;\n if(memo[target]!=... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n int combinationSum4(vector<int>& nums, int target) {\n vector<int> memo(target+1, -1);\n function<int(int)> dfs = [&](int n) -> int {\n if (n == 0) return 1;\n int &temp = memo[n];\n if (temp != -1) return temp;\n temp... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n \n map<int,int> cache;\n \n int search(int target, vector<int> &nums){\n if(target == 0) {return 1;}\n if(target < 0) return 0;\n\n auto itr = cache.find(target);\n if(itr != cache.end()){\n return itr->second;\n }\n\n ... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "#include <vector>\n#include <unordered_map>\nusing namespace std;\n\nclass Solution {\npublic:\n // Memoization map to store the results of subproblems\n unordered_map<int, int> memo;\n \n int helper(const vector<int>& nums, int target) {\n // Base case: If the target is zero, there is e... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<int,int> results;\n int combinationSum4(vector<int>& nums, int target) {\n return combSumFrom(nums, target);\n }\n int combSumFrom(vector<int>& nums, int target) {\n if (target == 0) {\n return 1;\n }\n if (target ... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n int dfs(int target,vector<int>&nums,int sum,unordered_map<int,int>& mp1){\n \n if(sum>target)return 0;\n if(sum==target)return 1;\n int a=0;\n if(mp1.find(sum)!=mp1.end()) return mp1[sum];\n for(int i=0;i<nums.size();i++){\n a+=dfs... |
377 | <p>Given an array of <strong>distinct</strong> integers <code>nums</code> and a target integer <code>target</code>, return <em>the number of possible combinations that add up to</em> <code>target</code>.</p>
<p>The test cases are generated so that the answer can fit in a <strong>32-bit</strong> integer.</p>
<p>&... | 3 | {
"code": "class Solution {\npublic:\n int dfs(int target, vector<int>& nums, int sum,\n unordered_map<int, int>& mp1) {\n if (sum > target) return 0;\n if (sum == target) return 1;\n int a = 0;\n if (mp1.find(sum) != mp1.end())\n return mp1[sum];\n for (int i =... |
165 | <p>Given two <strong>version strings</strong>, <code>version1</code> and <code>version2</code>, compare them. A version string consists of <strong>revisions</strong> separated by dots <code>'.'</code>. The <strong>value of the revision</strong> is its <strong>integer conversion</strong> ignoring leading zeros.<... | 0 | {
"code": "#include <ranges>\n\nclass Solution {\npublic:\n int compareVersion(string version1, string version2) {\n auto r1 = views::split(version1, '.');\n auto r2 = views::split(version2, '.');\n\n auto it1 = r1.begin(), it2 = r2.begin();\n while (it1 != r1.end() || it2 != r2.end()) ... |
165 | <p>Given two <strong>version strings</strong>, <code>version1</code> and <code>version2</code>, compare them. A version string consists of <strong>revisions</strong> separated by dots <code>'.'</code>. The <strong>value of the revision</strong> is its <strong>integer conversion</strong> ignoring leading zeros.<... | 0 | {
"code": "class Solution {\npublic:\n static int compareVersion(string& v1, string& v2) {\n const int n1=v1.size(), n2=v2.size();\n int x1=0, x2=0;\n for(int i=0, j=0; i<n1 || j<n2; i++, j++){\n while(i<n1 && v1[i]!='.'){\n x1=10*x1+(v1[i++]-'0');\n }\n ... |
165 | <p>Given two <strong>version strings</strong>, <code>version1</code> and <code>version2</code>, compare them. A version string consists of <strong>revisions</strong> separated by dots <code>'.'</code>. The <strong>value of the revision</strong> is its <strong>integer conversion</strong> ignoring leading zeros.<... | 2 | {
"code": "class Solution {\npublic:\n int strToDec(string s){\n int num=0;\n int n=s.length();\n // cout<<s<<\" \";\n for(int i=n-1;i>=0;i--){\n num+=(s[i]-'0')*pow(10,n-i-1);\n }\n return num;\n }\n int compareVersion(string version1, string version2) {\... |
165 | <p>Given two <strong>version strings</strong>, <code>version1</code> and <code>version2</code>, compare them. A version string consists of <strong>revisions</strong> separated by dots <code>'.'</code>. The <strong>value of the revision</strong> is its <strong>integer conversion</strong> ignoring leading zeros.<... | 2 | {
"code": "class Solution {\npublic:\n int compareVersion(string v1, string v2) {\n int i=0;\n int j=0;\n\n while (i<v1.size() || j<v2.size()){\n string m=\"\";\n while(i<v1.size()&& v1[i]!='.' ){\n m+=v1[i];\n i++;\n }\n strin... |
165 | <p>Given two <strong>version strings</strong>, <code>version1</code> and <code>version2</code>, compare them. A version string consists of <strong>revisions</strong> separated by dots <code>'.'</code>. The <strong>value of the revision</strong> is its <strong>integer conversion</strong> ignoring leading zeros.<... | 2 | {
"code": "class Solution {\npublic:\n int compareVersion(string version1, string version2) {\n vector<int> v1 = splitVersion(version1);\n vector<int> v2 = splitVersion(version2);\n \n int n = max(v1.size(), v2.size());\n for (int i = 0; i < n; i++) {\n int num1 = i < ... |
165 | <p>Given two <strong>version strings</strong>, <code>version1</code> and <code>version2</code>, compare them. A version string consists of <strong>revisions</strong> separated by dots <code>'.'</code>. The <strong>value of the revision</strong> is its <strong>integer conversion</strong> ignoring leading zeros.<... | 3 | {
"code": "class Solution {\npublic:\n vector<string> getToken(string version)\n {\n stringstream ss(version);\n\n string token=\"\";\n vector<string>tokens;\n while(getline(ss,token,'.'))\n {\n tokens.push_back(token);\n }\n return tokens;\n }\n ... |
165 | <p>Given two <strong>version strings</strong>, <code>version1</code> and <code>version2</code>, compare them. A version string consists of <strong>revisions</strong> separated by dots <code>'.'</code>. The <strong>value of the revision</strong> is its <strong>integer conversion</strong> ignoring leading zeros.<... | 3 | {
"code": "class Solution {\npublic:\n int compareVersion(string version1, string version2) {\n map<char,int>mp;\n \n mp['0']=0;\n mp['1']=1;\n mp['2']=2;\n mp['3']=3;\n mp['4']=4;\n mp['5']=5;\n mp['6']=6;\n mp['7']=7;\n ... |
165 | <p>Given two <strong>version strings</strong>, <code>version1</code> and <code>version2</code>, compare them. A version string consists of <strong>revisions</strong> separated by dots <code>'.'</code>. The <strong>value of the revision</strong> is its <strong>integer conversion</strong> ignoring leading zeros.<... | 3 | {
"code": "class Solution {\npublic:\n int compareVersion(string version1, string version2) {\n int ans = 0;\n vector<int> v1;\n vector<int> v2;\n\n int prevD = 0;\n for(int i = 0; i < version1.size(); i++) {\n if(version1[i] == '.') {\n v1.push_back(sto... |
165 | <p>Given two <strong>version strings</strong>, <code>version1</code> and <code>version2</code>, compare them. A version string consists of <strong>revisions</strong> separated by dots <code>'.'</code>. The <strong>value of the revision</strong> is its <strong>integer conversion</strong> ignoring leading zeros.<... | 3 | {
"code": "class Solution {\npublic:\n\n vector<string> split(string s, char c){\n vector<string> parts;\n string part;\n istringstream in(s);\n\n while(getline(in, part, c)){\n parts.push_back(part);\n }\n return parts;\n }\n\n int compareVersion(string v... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 0 | {
"code": "class Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n long long n = numerator, d = denominator;\n if (d < 0) {\n n = -n;\n d = -d;\n }\n string res = (n >= 0 ? \"\" : \"-\") + to_string(abs(n)/d);\n if (n%d == 0)... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 0 | {
"code": "class Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n long long n = numerator, d = denominator;\n if (d < 0) {\n n = -n;\n d = -d;\n }\n string res = (n >= 0 ? \"\" : \"-\") + to_string(abs(n)/d);\n if (n%d == 0)... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 0 | {
"code": "class Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n long long n = numerator, d = denominator;\n if (d < 0) {\n n = -n;\n d = -d;\n }\n string res = (n >= 0) ? to_string(n/d) : (\"-\" + to_string(-n/d));\n if (n... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 0 | {
"code": "typedef long long ll;\n\nclass Solution {\npublic:\n ll sign(ll x) {\n if (x < 0) return -1;\n else if (x > 0) return 1;\n else assert(false);\n }\n \n string add_sign(string str, ll sign_res) {\n if (str != \"0\" && sign_res < 0) return \"-\" + str;\n else return str;\n }\n \n string... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 0 | {
"code": "class Solution {\npublic:\n string fractionToDecimal(int nu, int de) {\n if (nu == 0) return \"0\";\n string res;\n unordered_map<long long int, int> mp;\n bool flag = ((nu < 0 && de >= 0) || (nu >= 0 && de < 0));\n long long numerator = nu;\n long long denomi... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 0 | {
"code": "class Solution {\npublic:\n void solve(string& ans, long long numerator, long long denominator) {\n unordered_map<long long, int> pos; // To store the positions of remainders\n string fractionalPart;\n int index = 0;\n\n // Start processing fractional part\n fractionalPart += '.';\n\n w... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 0 | {
"code": "class Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n if(numerator == 0) return \"0\";\n string answer;\n answer += ((numerator < 0) ^ (denominator < 0)) ? \"-\" : \"\";\n numerator = abs(numerator);\n denominator = abs(denominator);\... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 0 | {
"code": "class Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n if (numerator == 0)\n return \"0\";\n \n string result;\n if ((numerator < 0) != (denominator < 0))\n result += \"-\";\n \n long n = abs((long)numerato... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 0 | {
"code": "class Solution {\npublic:\n string fractionToDecimal(long long int n, long long int d) {\n if(n == 0){\n return \"0\";\n }\n string ans = \"\";\n if(n<0 ^ d<0){\n ans += '-';\n }\n n = abs(n);\n d = abs(d);\n ans += to_string(... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 1 | {
"code": "class Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n string ans;\n \n if(!numerator){\n return \"0\";\n }\n\n if((numerator > 0) ^ (denominator>0)){\n ans += '-';\n }\n long numer = labs(numerator)... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 1 | {
"code": "class Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n if (numerator == 0) return \"0\";\n \n string result;\n if ((numerator<0)^(denominator<0)){\n result+=\"-\";//negative numbers\n }\n\n long long num=abs((long lon... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 2 | {
"code": "class Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n string ans;\n int c=0;\n if(numerator==0)\n {\n return \"0\";\n }\n if(denominator==0)\n {\n return \"undefined\";\n }\n long long... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 2 | {
"code": "class Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n unordered_map<long,int>mp;\n string ans=\"\";\n int c=0;\n if(numerator==0)\n {\n return \"0\";\n }\n if(denominator==0)\n {\n return \"u... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 3 | {
"code": "class Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n if(!numerator) return \"0\";\n string ans = \"\";\n if (numerator > 0 ^ denominator > 0) ans += '-';\n long num = labs(numerator), den = labs(denominator);\n long q = num / den;\n ... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 3 | {
"code": "class Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n string decimal = ((numerator > 0 && denominator < 0) || (numerator < 0 && denominator > 0) ? \"-\" : \"\") + to_string(abs((long long)numerator / (long long)denominator));\n long long remainder = abs((... |
166 | <p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.<... | 3 | {
"code": "class Solution {\npublic:\n\tstatic std::string fractionToDecimal(int numerator, int denominator) noexcept {\n\t\t// 0 divided by anything is still 0\n\t\tif (!numerator) {\n\t\t\treturn \"0\";\n\t\t}\n\n\t\t// check for result's sign\n\t\tstd::string ans;\n\t\tbool isNegative = (numerator > 0) ^ (denomina... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.