id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> ans;\n void getSolution(int n, int k, int index, vector<int> temp, int val){\n if(index == k){\n ans.push_back(temp);\n return;\n }\n for(int i=val; i<=n; i++){\n temp[index] = i;\n getSol... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution\n{\n std::vector<std::vector<int>> _combinations;\n int _n;\n int _k;\n\n void combineBacktrack(std::vector<int> combination)\n {\n int sizeTail = _k - combination.size();\n\n if (sizeTail == 0)\n {\n _combinations.emplace_back(std::move(combina... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n\n void func(int ind, vector<int> temp, vector<int> &v, int k, vector<vector<int>> &ans){\n if(k == 0){\n ans.push_back(temp);\n return;\n }\n for(int i=ind+1;i<v.size();i++){\n temp.push_back(v[i]);\n func(i, te... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n/*\n int factorial(int number) {\n int results = 1;\n while (number != 0) {\n results *= number;\n number--;\n }\n return results;\n }\n/*\n static bool vec_compare(const vector<int>& first, const vector<int>& second) {\n... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\nprivate:\n vector<vector<int>> combination;\n\n void add_combination(vector<int> data_list, int start_index, int end_index, int remain_index){\n if(remain_index == 0){\n combination.push_back(data_list);\n return;\n }\n \n for(int i ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void combinations(int n,int k,vector<vector<int>>& v,int i,vector<int> result){\n \n if (result.size()==k && k!=0){\n v.push_back(result);\n return;\n }\n\n for (int j=i;j<=n;j++){\n \n result.push_back(j)... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n int X[100];\n vector<vector<int>> res;\n void Try(int i, int n, int k){\n for(int j = X[i - 1] + 1; j <= n - k + i; j++){\n X[i] = j;\n if(i == k){\n vector<int> tmp;\n for(int u = 1; u <= k; u++){\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n queue<vector<int>> q;\n vector<vector<int>> res;\n q.push({});\n\n for (int i = 1; i <= n; ++i) {\n int size = q.size();\n for (int j = 0; j < size; ++j) {\n if (i +... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n queue< vector<int> > q;\n for(int i=1; i<=n-k+1; i++){\n q.push(vector<int> (1, i));\n }\n for(int i=n-k+2; i<=n; i++){\n vector<int> vec;\n int qSize;\n qSiz... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\n vector<vector<int>> ans;\npublic:\n vector<vector<int>> combine(int n, int k ) {\n vector<int> v;\n int r,val=1;\n func(n,k,v,r=1,val);\n return ans;\n }\n void func(int n,int k, vector<int> v,int r,int val)\n {//{if(k+1==r)\n // {ans.push_... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n\n void backtracking(int i, vector<int> cur, vector<vector<int>> &ans, int n, int k, int s){\n cur.push_back(0);\n for(int j = s + 1; j <= n; ++j){\n cur[cur.size() - 1] = j;\n if(k == i){\n ans.push_back(cur);\n }\... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void check(vector<int>&nums,int k,vector<vector<int>>&ans,vector<int>&temp,vector<int>visit,int index)\n {\n if(temp.size()==k)\n {\n ans.push_back(temp);\n return ;\n }\n for(int i=index;i<nums.size();i++)\n {\n if(visit[i]==0)\n {... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<int> allNInts;\n for(int i = 1; i <= n; i++) {\n allNInts.push_back(i);\n }\n vector<vector<int>> answer;\n vector<int> currValues;\n int index = 0;\n findAllCombi... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\nvector<vector<int>>ans;\nset<vector<int>>se;\nvector<int> temp;\nvoid solve(int s,int n,int k) {\n if (temp.size() == k) {\n vector<int>v3 = temp;\n sort(v3.begin(), v3.end());\n se.insert(v3);\n return;\n }\n for (int i = s; i <= ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\n vector<vector<int>> res;\n void fun(int n, int k, int i, vector<int> temp) {\n if (i!=0) {\n temp.push_back(i);\n k--;\n }\n if (k==0) {\n res.push_back(temp);\n return ;\n }\n for(int j=i+1;j<=(n-k+1);j++) {\n fun(n, k, j, tem... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\nprivate:\n int n;\n std::vector<std::vector<int>> combi... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n queue<vector<int>> choices;\n for(int i = 1; i <= n; i++) {\n vector<int> vec = { i };\n vec.reserve(k);\n choices.emplace(vec);\n }\n while(choices.front().size() < k) ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n queue<vector<int>> choices;\n for(int i = 1; i <= n; i++) {\n vector<int> vec = { i };\n vec.reserve(k);\n choices.emplace(move(vec));\n }\n while(choices.front().size()... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void helper(int i, int n, int k, \n vector<vector<int>> & allCombine, vector<int> curCombine) {\n if (curCombine.size() == k) {\n vector<int> copy = curCombine;\n allCombine.push_back(copy);\n return;\n }\n if (i > ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void combineLoop (int n, int k, int startIndex, vector<int> vec, vector<vector<int>>* res){\n if(vec.size() == k){\n res->push_back(vec);\n }\n else{\n for(int i=startIndex; i<=n; i++){\n vec.push_back(i);\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void backtrack(int i, vector<int> comb, vector<vector<int>> &ans, int n, int k){\n if(i == k){\n ans.push_back(comb);\n return;\n }\n\n int start = comb.size() == 0 ? 1 : comb.back() + 1;\n vector<int> temp;\n\n for(int... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<int>>& ans,vector<int>& curr,int k,int n,vector<int> used,int start){\n if(curr.size()==k){\n ans.push_back(curr);\n return;\n }\n for(int i=start;i<=n;i++){\n if(used[i]) continue;\n cu... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\nvector<vector<int>>res;\n\nint newn;\n void helper(int i,int k,vector<int>temp)\n {\n if(temp.size()==k)\n {\n res.push_back(temp);\n return;\n }\n \n for(int j=i+1;j<=newn;j++)\n {\n temp.push_back(j);\n helper(j,k,temp);\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\n vector<vector<int>> ans;\npublic:\n vector<vector<int>> combine(int n, int k ) {\n vector<int> v;\n int r,val=1;\n func(n,k,v,r=1,val);\n return ans;\n }\n void func(int n,int k, vector<int> v,int r,int val)\n {if(k+1==r)\n {ans.push_back... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n\n vector<vector<int>> out;\n\n vector<vector<int>> combine(int n, int k) {\n\n for (int i = 1; i <= n-k+1; i++) {\n vector<int> temp({i});\n combineHelper(temp, i+1, n, k);\n }\n\n return out;\n }\n\n void combineHelper(vect... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n // k is the length of each vector<int>\n // n is the right end of the range of values that the values can be chosen from\n vector<vector<int>> res;\n vector<int> rem, cur;\n for (int i = 1; i <= ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> res;\n vector<vector<int>> combine(int n, int k) {\n vector<bool> visited(n+1, false);\n vector<int> path(k);\n dfs(n, k, path, visited);\n return res;\n }\n void dfs(int n, int k, vector<int> path, vector<bool> visited){\n... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n // k is the length of each vector<int>\n // n is the right end of the range of values that the values can be chosen from\n vector<vector<int>> res;\n vector<int> rem, cur;\n for (int i = 1; i <= ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n // k is the length of each vector<int>\n // n is the right end of the range of values that the values can be chosen from\n vector<vector<int>> res;\n vector<int> rem, cur;\n for (int i = 1; i <= ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> res;\n\nvoid help(vector<int> a,int idx,vector<int> &ans,int k){\n if(ans.size() == k){\n res.push_back(ans);\n return;\n }\n for(int i = idx ;i<a.size();i++){\n ans.push_back(a[i]);\n h... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void dfs_com(int n, int k, int pos, vector<int> cur, set<vector<int>>& s)\n{\n if (k == cur.size())\n {\n s.insert(cur);\n return;\n }\n\n for (int i = pos; i <= n; ++i)\n {\n cur.push_back(i);\n dfs_com(n, k, i + 1, cur, s);\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n queue< vector<int> > q;\n for(int i=1; i<=n-k+1; i++){\n q.push(vector<int> (1, i));\n }\n for(int i=n-k+2; i<=n; i++){\n vector<int> vec;\n int qSize;\n qSiz... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define pb push_back\n\n\n\nclass Solution {\npublic:\n vector<vector<int>> result;\n vector<vector<int>> combine(int n, int k) {\n \n vector<int> nums(n);\n iota(nums.begin(), nums.end(), 1);\n\n int itr=0;\n vector... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> ans;\n void process(vector<int> p, int n, int k) {\n if (k == 0) {\n ans.push_back(p);\n return;\n }\n for (int i = 1; i <= n - k + 1; ++i) {\n if (p.size() == 0) {\n vector<int> tmp =... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n set<vector<int>> st;\n void f(vector<int> &v, int i, int n, int k){\n if(v.size() == k){\n st.insert(v);\n return;\n }\n if(i > n) return;\n f(v,i+1,n,k);\n v.push_back(i);\n f(v,i+1,n,k);\n v.pop_back(... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n set<vector<int>> st;\n void f(vector<int> &v, int i, int n, int k){\n if(v.size() == k){\n st.insert(v);\n return;\n }\n if(i > n) return;\n f(v,i+1,n,k);\n v.push_back(i);\n f(v,i+1,n,k);\n v.pop_back(... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> ans;\n void process(vector<int> p, int n, int k) {\n if (k == 0) {\n p.erase(p.begin());\n ans.push_back(p);\n return;\n }\n for (int i = p[p.size()-1]+1; i <= n-k+1; ++i) {\n vector<i... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> ans;\n void process(vector<int> p, int n, int k) {\n if (k == 0) {\n p.erase(p.begin());\n ans.push_back(p);\n return;\n }\n for (int i = p[p.size()-1]+1; i <= n-k+1; ++i) {\n vector<i... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<int> arr;\n set<vector<int>> s;\n vector<int> ds;\n map<int, bool> mpp;\n vector<vector<int>> res;\n \n for (int i = 1; i <= n; i++) {\n arr.push_back(i); // Fill... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n deque<vector<int>> dq;\n bt(n, k, dq);\n return vector(dq.begin(), dq.end());\n }\n\n void bt(int n, int k, deque<vector<int>>& dq) {\n // cout << \"k: \" << k << endl;\n if (k == 1) {\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void combine_help(vector<vector<int>> &sol, vector<int> temp, int num, int k, int n){\n if(temp.size() < k){\n temp.push_back(num);\n if(temp.size() == k){\n sol.push_back(temp);\n }\n for(int i = num+1; i <= n... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> result;\n int sz ;\n int cap;\n void fuc(vector<int> current,vector<bool> has){\n if(current.size() == sz){\n result.push_back(current);\n return;\n }\n int last = 0;\n if(current.size() > 0)last =... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<vector<int>> result;\n if(!k) return vector<vector<int>> (1, vector<int>());\n\n vector<vector<int>> prevResult = combine(n, k-1);\n\n for(auto &prevRes : prevResult) {\n for(int i=1; ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n if (k == 1) {\n vector<vector<int>> combs;\n for (int i = 1 ; i <= n; ++i) {\n combs.push_back({i});\n }\n return combs;\n }\n\n auto rest_combs = com... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n // k is the length of each vector<int>\n // n is the right end of the range of values that the values can be chosen from\n vector<vector<int>> res;\n vector<int> rem, cur;\n for (int i = 1; i <= ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n\n\n void fun(int n, int r, vector<vector<int>> &ans, int idx, int curr_count, vector<int> curr_vector)\n{\n if(idx== n+1)return;\n if(curr_count==r)\n {\n ans.push_back(curr_vector);\n return;\n }\n \n for(int i=idx; i<n+1;i++)\n {\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\nprivate:\n vector<vector<int>> ans;\n void combination(int num, int k, int i, int n,vector<int>nums)\n {\n nums.push_back(num);\n i++;\n if(i == k)\n {\n ans.push_back(nums);\n return;\n }\n for(int j = num+1; j<=n; ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n for (int i = 1; i <= n; i++) {\n vector<int> comb;\n myCombine(i, n, k, comb);\n if (n - i + 1 == k) {\n break;\n }\n }\n return results; \n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n if (computed[n][k]) {\n return result[n][k];\n }\n if (k > n) {\n return save_result(n, k, {});\n }\n if(k == 0 && n == 0) {\n return save_result(n, k, {{}});\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n if (computed[n][k]) {\n return result[n][k];\n }\n if (k > n) {\n return save_result(n, k, {});\n }\n if(k == 0 && n == 0) {\n return save_result(n, k, {{}});\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int ind, vector<vector<int>>& ans, vector<int> nums, int k,\n vector<int>& temp) {\n if (ind >= nums.size() || k == 0) {\n ans.push_back(temp);\n return;\n }\n // take\n for (int i = ind; i < nums.size(); ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\n void solve(int &n,int &k,int idx,vector<int> &cur,vector<vector<int>> &ans) {\n if(cur.size() == k) {\n ans.push_back(cur);\n return;\n }\n for(int i = idx;i <= n;i++) {\n cur.push_back(i);\n solve(n,k,i+1,cur,ans);\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\n void recursive_loop(vector<vector<int>> &combinations, vector<int> choosed_tems, int last_choice, int n, int k)\n {\n if (k==0)\n {\n combinations.push_back(choosed_tems);\n }\n else if (n - last_choice < k)\n {\n return;\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void func(int i,int n,vector<int> &temp,int k,set<vector<int>>& ans)\n {\n if(temp.size()==k)\n {\n ans.insert(temp);\n }\n if(i==n+1)\n {\n return ;\n }\n \n temp.push_back(i);\n func(i+1,n,temp,k,ans);\n temp.pop_back();\n func(i+1,n,temp,k,ans... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void func(int i,int n,vector<int> &temp,int k,set<vector<int>>& ans)\n {\n if(temp.size()==k)\n {\n ans.insert(temp);\n }\n if(i==n+1)\n {\n return ;\n }\n \n temp.push_back(i);\n func(i+1,n,temp,k,ans);\n temp.pop_back();\n func(i+1,n,temp,k,ans... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n\n void backtrack(int start, vector<int> visited, int depth, vector<vector<int>> &ans, int k) {\n int n = visited.size();\n if(depth == k) {\n vector<int> l;\n for(int i = 0; i < visited.size(); i++) {\n if(visited[i] == 1)\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\nvoid solver(int n,int k,vector<int>&v,set<vector<int>>&ans){\n if(n<=0){\n // sort(v.begin(),v.end());\n\n if(v.size()==k) ans.insert(v);\n\n return ;\n }\n \n // if(v.size()>k) return ;\n v.push_back(n);\n solver(n-1,k,v,ans);\n v.pop_back(... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n\n void helper(vector<int>&nums,int index,vector<int>&curr,vector<vector<int>>&all){\n if(nums.size() == index){\n all.push_back(curr);\n return;\n }\n curr.push_back(nums[index]);\n helper(nums,index+1,curr,all);\n curr... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<vector<int>>result;\n vector<int> nums;\n vector<int> temp;\n for(int i=1;i<=n;i++)\n nums.push_back(i);\n int start=0;\n backtracking(result, nums, temp, start, k);\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> ans;\n void combination(vector<int> nums,int k,vector<int> res){\n if(k==0)\n {\n ans.push_back(res);\n return;\n }\n for(int i=0;i<nums.size();i++){\n vector<int> subVector;\n res.... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<vector<vector<int>>>dp(k+1,vector<vector<int>>{});\n dp[0]={{}};\n for(int new_el=1; new_el<=n; ++new_el){\n for(int sz=k-1;sz>=0;sz--){\n for(int i=0; i<dp[sz].size();++i){\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\n\n\nclass Solution {\n \npublic:\n vector<vector<int>> answer;\n void dfs(vector<int>v, int n , int k , int cnt , int idx){\n for(int i = idx ; i<=n ; i++){\n if(cnt == k){\n answ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<vector<int>> out(1);\n size_t ok = 0;\n for (size_t ki = 0; ki < k; ki++) {\n size_t on = out.size();\n for (size_t oi = ok; oi < on; oi++) {\n for (size_t i = 0; i ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> sol;\n void choose(vector<int> options, vector<int> v, int n, int k, int min) {\n // cout << \"choose()\\n\";\n if (k < 1) {\n // cout << \"Adding\\n\";\n sol.push_back(v);\n return;\n }\n for... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> ans;\n void makeCombinations(vector<int> curr, vector<int> nums, int k, int index){\n if(curr.size()==k){\n ans.push_back(curr);\n return;\n }\n for(int i=index;i<nums.size();i++){\n curr.push_back(n... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& ans, vector<int> subAns, int n, int k, int current) {\n if(current>n) return;\n vector<int> temp(subAns);\n temp.push_back(current);\n if(temp.size()==k) {\n ans.push_back(temp);\n return;\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n map<pair<int,int>,vector<vector<int>>> M;\n vector<vector<int>> calc(int n,int k){\n if(M.find({n,k}) != M.end()){\n return M[{n,k}];\n }\n vector<vector<int>> result1 = calc(n-1,k);\n vector<vector<int>> result2 = calc(n-1,k-1);\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n map<pair<int,int>,vector<vector<int>>> M;\n vector<vector<int>> calc(int n,int k){\n if(M.find({n,k}) != M.end()){\n return M[{n,k}];\n }\n vector<vector<int>> result1 = calc(n-1,k);\n vector<vector<int>> result2 = calc(n-1,k-1);\n ... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void help(vector<vector<int>>& ans,vector<int> temp,int n,int k,int x){\n if(temp.size()==k){\n ans.push_back(temp);\n return;\n }\n for(int i=x;i<=min(n,(n-k+1+x));i++){\n vector<int> temp1(temp);\n temp1.push_... |
77 | <p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>
<p>You may return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<... | 3 | {
"code": "class Solution {\npublic:\n void dp(int n,int k,int size,vector<int> arr, vector<vector<int>> &ans,int last)\n {\n if(size==k)\n {\n ans.push_back(arr);\n return;\n }\n else if(last==n)\n {\n return;\n }\n for(int i=las... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n int n=nums.size();\n int Mask=1<<n;\n vector<vector<int>> powerSet(Mask);\n for (unsigned m=0; m<Mask; m++){\n powerSet[m].reserve(popcount(m));\n for(int i=0; i<n; i++){\n ... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 0 | {
"code": "class Solution {\npublic:\n void swati(vector<int>& nums,vector<vector<int>>& unique ,vector<int>& subsets,int start){\n\n unique.push_back(subsets);\n for(int i =start;i<nums.size();i++){\n subsets.push_back(nums[i]);\n swati(nums,unique,subsets,i+1);\n sub... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n int n=nums.size();\n int Mask=1<<n;\n vector<vector<int>> powerSet(Mask);\n for (unsigned m=0; m<Mask; m++){\n powerSet[m].reserve(popcount(m));\n for(int i=0; i<n; i++){\n ... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n int l = nums.size() ;\n int numberofsubsets = 1<<l ;//{2^l}\n int i,j ; vector<int>output; vector<vector<int>>ans ;\n for(i=0;i<numberofsubsets;i++)\n {\n output.clear() ;\n ... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 0 | {
"code": "class Solution {\npublic:\n void solve(int index,int &n, vector<vector<int>>&ans,vector<int>& nums,vector<int>&li)\n {\n if(index >= n)\n {\n ans.push_back(li);\n return;\n }\n\n //Pick\n li.push_back(nums[index]);\n solve(index+1,n,ans,... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n int n=nums.size();\n int Mask=1<<n;\n vector<vector<int>> powerSet(Mask);\n for (unsigned m=0; m<Mask; m++){\n powerSet[m].reserve(popcount(m));\n for(int i=0; i<n; i++){\n ... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 0 | {
"code": "class Solution {\n// void solve(int idx, vector<int>& nums, vector<vector<int>> &result,vector<int> &temp){\n// if(idx >= nums.size()){\n// result.push_back(temp);\n// return;\n// }\n\n// temp.push_back(nums[idx]); //include\n// solve(idx+1,nums,result,temp);\n// temp.po... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 0 | {
"code": "class Solution {\npublic:\nvoid backtrack(vector<vector<int>>& res, vector<int>& temp, vector<int>& nums, int start)\n{\n res.push_back(temp);\n int i;\n for(i=start;i<nums.size();i++)\n {\n temp.push_back(nums[i]);\n backtrack(res,temp,nums,i+1);\n temp.pop_back();\n }\... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "auto init = []() {\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n return 0;\n}();\n\n#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n void calcSubset(vector<int> &nums, set<vector<int>> &A, vector<int> &curSet, int index) {\n A.insert(curSet);\n for (s... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> result;\n\n void computeSubset(vector<int>& nums, vector<int> v, int nextIndex)\n {\n result.push_back(v);\n for (int i = nextIndex; i < nums.size();i++)\n {\n v.push_back(nums[i]);\n computeSubset(nums, v, i... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> possSubsets(vector<int>& nums, int n)\n {\n if(n==0)\n return {{}};\n vector<vector<int>> temp = possSubsets(nums,n-1), ans;\n ans=temp;\n for(auto t:temp)\n {\n t.push_back(nums[n-1]);\n a... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> global{{}};\n void insert(vector<int>& nums, int i, vector<int> tmp) {\n for(i; i < nums.size(); i++) {\n tmp.push_back(nums[i]);\n insert(nums, i + 1, tmp);\n global.push_back(tmp);\n tmp.pop_back();\n... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> recursive(vector<int> nums, int &i){\n if(i == nums.size()) return {{}};\n vector<vector<int>> result;\n int store_i = i++;\n vector<vector<int>> rest = recursive(nums, i);\n for(auto a : rest){\n result.push_b... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> recursive(vector<int> nums, int &i){\n if(i == nums.size()) return {{}};\n vector<vector<int>> result;\n int store_i = i++;\n vector<vector<int>> rest = recursive(nums, i);\n for(auto a : rest){\n result.push_b... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n vector<vector<int>> result(1);\n vector<int> output;\n GetSubsets(result, nums, nums.size(), output);\n return result;\n }\nprivate:\n void GetSubsets(vector<vector<int>>& result, vector<int>... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\n\n vector<vector<int>> ans;\n\npublic:\n\n vector<vector<int>> subsets(vector<int>& nums) {\n\n ans.clear();\n\n queue<pair<vector<int>, int>> q;\n\n q.push({{}, 0});\n\n while(!q.empty()){\n\n auto k = q.front();\n\n q.pop();\n\n ... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& a) {\n int n=a.size();\n vector<vector<int>> ans;\n queue<pair<vector<int>, int>>q;\n q.push({{}, 0});\n while(!q.empty()){\n auto k = q.front();\n q.pop();\n auto idx... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\n vector<vector<int>> ans;\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n ans.clear();\n queue<pair<vector<int>, int>> q;\n q.push({{}, 0});\n while(!q.empty()){\n auto k = q.front();\n q.pop();\n auto vec = ... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\n vector<vector<int>> ans;\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n ans.clear();\n queue<pair<vector<int>, int>> q;\n q.push({{}, 0});\n while(!q.empty()){\n auto k = q.front();\n q.pop();\n auto vec = ... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n// vector<vector<int>> ans;\n// vector<vector<int>> subsets(vector<int>& nums) {\n// ans.clear();\n// queue<pair<vector<int>, int>> q;\n// q.push({{}, 0});\n// while(!q.empty()){\n// auto k = q.front();\n// q.pop()... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\nvoid func(vector<vector<int>>& res, vector<int> &v, vector<bool> &done, vector<int>& a, int d, int t){\n int n = a.size();\n int l = v.size();\n if(d==1)\n res.push_back(v);\n if(l==n) return;\n for(int i=0; i<n; i++) {\n i... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n void recursion(int sz, vector<vector<int>>&ans, vector<int>&cp, vector<int>& r)\n {\n if(r.size() == sz)\n {\n ans.push_back(r);\n return;\n }\n for(int i = 0;i<cp.size();i++)\n {\n r.push_back(cp[i]);\n ... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n vector<vector<int>> ans;\n vector<int> cur;\n for (int i = 0; i <= nums.size(); i++) {\n dfs(nums, i, 0, cur, ans);\n }\n return ans;\n }\nprivate:\n void dfs(vector<int>& n... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\nprivate:\n void getSubsets(set<vector<int>>& sets, int level)\n {\n if (level == 0)\n {\n sets.insert(vector<int>());\n return;\n }\n\n for (auto iset : sets)\n {\n if (iset.size() != level + 1)\n con... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n void backtrack(vector<vector<int>>& output, vector<int>& comb, vector<int> nums, int start, int k){\n if(comb.size() == k){\n output.push_back(comb);\n return;\n }\n for(int i = start; i < nums.size(); i++){\n comb.push_ba... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> output;\n int n, k;\n void backtrack(int first, vector<int> curr, vector<int>& nums) {\n // if the combination is done\n if (curr.size() == k) {\n output.push_back(curr);\n return; //missing\n }\n fo... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> output;\n int n, k;\n void backtrack(int first, vector<int> curr, vector<int>& nums) {\n // if the combination is done\n if (curr.size() == k) {\n output.push_back(curr);\n return; //missing\n }\n fo... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> output;\n int n, k;\n void backtrack(int first, vector<int> curr, vector<int>& nums) {\n // if the combination is done\n if (curr.size() == k) {\n output.push_back(curr);\n return; //missing\n }\n fo... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n vector<int>vect;\n vector<vector<int>>res;\n int n = nums.size();\n int limit = pow(2, n);\n\n for(int i=0; i<limit; i++){\n string s = \"\";\n int y=i;\n fo... |
78 | <p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p>
<p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>... | 2 | {
"code": "class Solution {\nprivate:\n void helper(vector<vector<int>>& result,\n const vector<int>& nums,\n vector<int> current,\n unordered_set<int> visited,\n int index) {\n for (int i = index; i < nums.size(); ++i) {\n int num = num... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.