id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int sz) {\n string ans = \"1\";\n for(int i = 0; i < sz - 1; i++){\n int n = ans.size();\n string new_ans = \"\";\n int id = 0, j = 0;\n while(id < n && j < n){\n while(j < n && ans[id...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string getRLE(string& str){\n int count = 1;\n string str1 = \"\";\n for(int i=0;i<str.size();i++){\n if((str[i]!=str[i+1] || str[i+1] == '\\0')){\n char cnt1 = count+'0';\n str1 = str1 + cnt1;\n str...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string fun(string s)\n {\n int n= s.length();\n string ans=\"\";\n int i=0;\n while(i<n)\n {\n int cnt = 0;\n int j=i+1;\n while(j<n)\n {\n if(s[i] != s[j])\n break...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int N) \n {\n if (N == 1) return \"1\";\n if (N == 2) return \"11\";\n\n std::string str = \"11\";\n\n for (int i = 3; i <= N; i++)\n {\n\t str = str + '$';\n\t std::string temp;\n\t int count = 1;\...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n == 1)\n return \"1\";\n if(n == 2)\n return \"11\";\n\n string s = \"11\";\n for(int i = 3; i <= n; i++){\n string t = \"\";\n s += '&';\n int count = 1;\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n\n // base case ->\n if(n == 1){\n return \"1\";\n }\n if(n == 2){\n return \"11\";\n }\n\n string temp;\n temp = \"11\";\n string s = \"\";\n \n for(int j = 3 ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n==1) return \"1\";\n if(n==2) return \"11\";\n string s=\"11\";\n for(int i=3;i<=n; i++){\n string t=\"\";\n int c=1;\n for(int j=1; j<=s.size(); j++){\n if(s[j]!=s[...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n == 1) return \"1\";\n if(n == 2) return \"11\";\n \n string s = \"11\"; \n \n for(int i = 3; i <= n; i++) { \n string t = \"\"; \n s = s + '&'; \n int count = 1; \n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n == 1)\n return \"1\";\n if(n == 2)\n return \"11\";\n string str = \"11\";\n for(int i= 3 ; i<=n ;i++)\n {\n string temp = \"\";\n str = str + \"#\";\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n == 1)return \"1\";\n if(n == 2)return \"11\";\n string s = \"11\";\n for(int i=3;i<=n;i++){\n string t = \"\";\n s = s + '&';\n int c=1;\n for(int j =1;j<s.size();j++){\...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n == 1) return \"1\";\n if(n == 2) return \"11\";\n \n string s = \"11\"; \n \n for(int i = 3; i <= n; i++) { \n string t = \"\"; \n s = s + '&'; \n int count = 1; \n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n==1) return \"1\";\n if(n==2) return \"11\";\n string s=\"11\";\n for(int i=3;i<=n;i++){\n string t=\"\";\n s=s+\"$\";\n int cnt=1;\n for(int j=1;j<s.length();j++){\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if (n == 1)\n return \"1\";\n string str = \"1\";\n for (int i = 2; i <= n; i++) {\n string temp = \"\";\n str = str + \"&\";\n int cnt = 1;\n for (int j = 1; j < str.len...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n // base case\n if(n==1)\n return \"1\";\n if(n==2)\n return \"11\";\n \n // take a string equals 11\n string str = \"11\";\n \n // now we need the value of nth term so ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n==1){\n return \"1\";\n }\n if(n==2){\n return \"11\";\n }\n string s=\"11\";\n for(int i=3;i<=n;i++){\n string t=\"\";\n s=s+'&';\n int c=1;\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string f(int n) {\n if (n == 1) {\n return \"1\";\n }\n\n string s = f(n - 1);\n\n string res;\n\n for (int i = 0, n = s.size(); i < n;) {\n int cnt = 0;\n char ch = s[i];\n while (i < n and s[i] =...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n map<int,string>mp;\n mp[1] = \"1\";\n mp[2] = \"11\";\n for(int i=3;i<=n;i++)\n {\n string temp = mp[i-1]+\"$\";\n int ct = 1;\n string ans = \"\";\n for(int j=1;j<tem...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n\n vector<pair<char,int>> getPairs(string s) {\n char prev='#';\n int count = 0;\n vector<pair<char,int>> v;\n for(int i=0;i<s.length();i++) {\n if(prev == s[i]) {\n count++;\n } else {\n if(prev !...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n vector<string>generateMap(string s){\n vector<string>ans;\n int i = 0,j=0;\n //cout<<s<<endl;\n while(i<s.size() && j<s.size()){\n int count = 0;\n while(j<s.size() && s[i] == s[j]){\n count++;\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> count(string s){\n cout<<s<<endl;\n vector<vector<int>> k;\n int i=0;\n while(i<s.length()){\n int key = s[i]-'0';\n int j=i,c=0;\n while(j<s.length()){\n if(s[j]!=s[i]){\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "vector<string> dp(31 , \"\");\nunordered_map<string ,string> cache;\n\nclass Solution {\nprivate:\n string rle(string s){\n if(s.size()==0) return \"\";\n if(cache.count(s)) return cache[s];\n string ans = \"\";\n int n =s.size();\n char last = s[0];\n int i = ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "vector<string> dp(31 , \"\");\nunordered_map<string ,string> cache;\n\nclass Solution {\nprivate:\n string rle(string s){\n if(s.size()==0) return \"\";\n if(cache.count(s)) return cache[s];\n string ans = \"\";\n int n =s.size();\n char last = s[0];\n int i = ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\n void solve(string s, int count, char ch, int idx, string &ans){\n if(idx==s.length()) {\n ans+=to_string(count)+ch;\n return;}\n if(s[idx]==ch){\n solve(s, count+1, ch, idx+1, ans);\n }\n else{\n ans+=to_string(count)...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n\nstring converter(int count, map<int, string> m1) {\n\n string ans = \"\";\n while (count != 0) {\n int mod = count % 10;\n ans += m1[mod];\n count = count / 10;\n }\n return ans;\n}\n\nstring final_ans(string nums, map<int,string> m1) {\n\nint n =...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int num) {\n if(num==1)return \"1\";\n num--;\n num--;\n\n string s = \"11\";\n while(num--){\n int n = s.length();\n int i=1;\n int count=1;\n string temp=\"\";\n whi...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "//Iteratively\nclass Solution {\npublic:\n string countAndSay(int n) {\n string ans;\n for(int i=1;i<=n;i++) {\n if(i==1) {\n ans = \"1\";\n } else {\n string tempans=\"\";\n int j;\n char prev=ans[0];\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n // string RLE(string x){\n // char prev = x[0] ;\n // int cnt = 0;\n // string ans=\"\" ;\n // for(int i = 0; i< x.length();i++){\n // if(x[i]==prev){\n // cnt++ ;\n // }\n // else{\n // ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string str=\"1\";\n if(n==1) return str;\n for(int j=1;j<n;j++){\n string ans=\"\";\n int cnt=1;\n for(int i=0;i<str.size();i++){\n if(i+1<str.size() && str[i]==str[i+1])cnt++;\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n\n string help1(string s)\n {\n int i=0;\n string res=\"\";\n while(i<s.length())\n {\n char ch=s[i];\n i++;\n int cnt=1;\n while(i<s.length()&&ch==s[i])\n {\n cnt++;\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n\n string rle(string s){\n string ans;\n int n = s.size();\n int i=0; \n\n while(i<n){\n\n char cur = s[i];\n int startind = i;\n int curcount = 0;\n while(i<n && s[i]==cur){\n curcount++;\n...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string func(int n){\n if(n==1) return \"1\";\n string str=func(n-1);\n string ans=\"\";\n int i=0;\n int j=0;\n while(i<str.length() && j<str.length()){\n char c=str[i];\n while(i<str.length() && str[i]==c){\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n==1)\n {return \"1\";}\n string s=countAndSay(n-1);\n string t=\"\";\n int i=0;\n while(s[i]!='\\0')\n {\n int c=1;\n while(s[i]==s[i+1])\n {i++;\n c++...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\n stack<char>st;\npublic:\n string countAndSay(int n) {\n if(n==1)\n return \"1\";\n string ans=countAndSay(n-1);\n string ans1=\"\";\n for(int i=0;i<ans.size();i++){\n int j=i;\n while(i<ans.size()&&ans[i]==ans[i+1]){\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\nstring cs(string m)\n{\n string ans;\n int n=m.size();\n \n char temp=m[0];\n int count=1;\n for(int i=1;i<n;++i)\n {\n if(temp==m[i])\n {\n ++count;\n }else{\n string q=to_string(count);\n ans=ans+q+temp;...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string ans = \"1\";\n for(int i(2); i <= n; ++i){\n int cnt = 1;\n int len = ans.length();\n char cur = ans[0];\n string str = \"\";\n for(int i(1); i < len; ++i){\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string ans;\n void rec(string start, int n){\n if(n==1){\n ans=start;\n return;\n }\n string sol=\"\";\n for(int i =0 ; i<start.size() ; i++){\n int count=0;\n for(int j=i ; j<start.size() ; j++ ){\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string prev = \"1\",temp;\n if(n==1)return prev;\n for(int i=1;i<n;i++){\n temp = \"\";\n int count=1;\n for(int j=1;j<prev.size();j++){\n if(prev[j]!=prev[j-1]){\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n // more eleegant way of writing \n string ans = \"1\";\n for (int i=1;i<n;i++)\n {\n // update your ans \n string entry=\"\";\n \n for (int i=0;i<ans.size();i++)\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n\n string str = \"1\";\n for (int i = 0; i < n - 1; i++) {\n int cnt = 1;\n string ans = \"\";\n\n for (int j = 1; j < str.size(); j++) {\n if (str[j] != str[j - 1]) {\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string RLE(string s){\n int i=0,j=0;\n char temp = s[i];\n string ans=\"\";\n while(j<s.size()){\n if(temp==s[j]){\n j++;\n }else{\n ans = ans + to_string(j-i) + temp;\n i=j;\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n //single element\n if(n == 1){\n return \"1\";\n }\n if(n == 2){\n return \"11\";\n }\n\n string s = \"11\";\n for(int i=3;i<=n;i++){\n string t =\"\";\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string s = \"1\";\n string res;\n int j;\n for(int i=1;i<n;i++){\n int c=1;\n res = \"\";\n \n for(j=1;j<s.length();j++){\n if(s[j]==s[j-1]){\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
0
{ "code": "class Solution {\npublic:\n void helper(vector<vector<int>>& answer, vector<int>& tracker, vector<int>& arr, size_t i, int target)\n {\n /*\n for (auto e: tracker)\n cout << e << ' ';\n cout << \" ---- \" << i << ' ' << target << endl;\n */\n if (target =...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
0
{ "code": "class Solution {\npublic:\n\n void combinationSum2(int index,vector<int>& candidates, int target, vector<vector<int>> &ans,vector<int> &temp){\n if(target==0){\n ans.push_back(temp);\n return;\n }\n if(index==candidates.size()){\n return;\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\npublic:\n\n vector<vector<int>> result;\n void helper(vector<int> &temp,vector<int>& candidates, int target, int i)\n {\n int sum=0;\n if(temp.size()>0)\n sum = accumulate(temp.begin(),temp.end(),0);\n if(sum==target)\n {\n result...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\npublic:\n\n vector<vector<int>> result;\n void helper(vector<int> &temp,vector<int>& candidates, int target, int i)\n {\n int sum=0;\n if(temp.size()>0)\n sum = accumulate(temp.begin(),temp.end(),0);\n if(sum==target)\n {\n result...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n sort(candidates.begin(), candidates.end());\n vector<vector<int>> ans;\n vector<int> t;\n function<void(int, int)> dfs = [&](int i, int s) {\n if (s == 0) {\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\npublic:\n int target_g;\n vector<vector<int>> sets;\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n cin.tie(NULL);\n ios_base::sync_with_stdio(false);\n\n vector<int> curr;\n target_g=target;\n\n helper(candidates, ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSumRec(vector<int>& candidates, int from,\n int target) {\n vector<vector<int>> combs;\n\n for (int i = from; i < candidates.size(); i++) {\n int val = candidates[i];\n\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\npublic:\n void combinations(vector<vector<int>>& ans, vector<int>& candidates, vector<int>& freqVals, int curr, int currSum, int target, int freqSum) {\n if (currSum>target) return;\n if (currSum == target) {\n vector<int> sums;\n for (int i=0; i<can...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> ans = {};\n vector<int> cur = {};\n void rec(vector<int> candidates,int target, int i){\n if (target==0){\n ans.push_back(cur);\n return;\n }\n for (int j = i; j < candidates.size(); j++){\n if (c...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> solution(const vector<int>& candidates, int target, int startIndex) {\n if (target <= 0) { return {}; }\n\n std::vector<std::vector<int>> answer;\n for (int i = startIndex; i < candidates.size(); i++) {\n if (target == candi...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n sort(candidates.begin(),candidates.end());\n vector<vector<vector<int>>> dp(target+1);\n dp[0] = {{}};\n for(int &i:candidates){\n for(int j=i;j<=target;j++){\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n vector<vector<vector<int> > > dp(target + 1);\n dp[0].push_back({});\n\n for (int i = 0; i < candidates.size(); i++) {\n for (int j = candidates[i]; j <= target; j++) {\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n sort(candidates.begin(), candidates.end());\n vector<vector<int>> ans;\n vector<int> t;\n function<void(int, int)> dfs = [&](int i, int s) {\n if (s == 0) {\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n vector<vector<int>> soln;\n vector<int> tmp_list;\n helper(candidates, soln, tmp_list, target, 0);\n return soln;\n }\n\n void helper(vector<int> &candidates, vector<...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\n\n vector<vector<int>> combinations;\n\n void buildCombination(vector<int>& candidates, int target, int candIdx, vector<int>& combination) {\n\n if (target == 0) {\n\n combinations.push_back(combination);\n return;\n }\n\n if (candIdx == ca...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
2
{ "code": "class Solution {\npublic:\n int dp[31][41];\n vector<vector<int>> ans;\n\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n memset(dp,-1,sizeof(dp));\n vector<int> vec;\n rec(candidates, 0, target, vec);\n return ans;\n }\n\n void rec(ve...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void recur(vector<vector<int>> & ans, vector<int> &candidates, int left, vector<int> curr, int pos) {\n int n = candidates.size();\n if(left == 0) {\n ans.push_back(curr);\n return;\n }else if(pos >= n || left <= 0) {\n re...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void solve(vector<int> &candidates, int target,int idx,int &n,vector<int> curr,vector<vector<int>> &ans)\n{\n if(target==0)\n {\n ans.push_back(curr);\n return;\n }\n if(idx==n)\n {\n return;\n }\n int i=0;\n \n while(1)\n {\...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void solve(vector<vector<int>>&ans,unordered_map<int,int>&mp,int index,vector<int>&arr,int target,vector<int>candidates){\n \n if(target==0){\n \n ans.emplace_back(arr);\n \n return;\n }\n \n \n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> ans;\n set<vector<int>> s;\n void back_considered_candidates(vector<int> &considered_candidates, int curr_candidate_sum , int target, vector<int>& candidates){\n // base condtion \n if(curr_candidate_sum == target) {\n vector...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\n\npublic:\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n int n = candidates.size();\n vector< vector<int> > dp[n][target+1];\n dp[0][0] = vector< vector<int> >(1);\n for(int i=0; i<n; i++) {\n for(int t = 0; t <= tar...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "void BT(int Sum, vector<int>& vec, vector<vector<int>>& res, vector<int>& can, int target, map<string, int>& visited)\n{\n if(Sum == target)\n {\n //res.push_back(vec);\n vector<int> tmp = vec;\n sort(tmp.begin(), tmp.end());\n string str=\"\";\n for(auto &x: tmp)\n...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "#include <vector>\n#include <queue>\n\nclass Solution {\npublic:\n std::vector<std::vector<int>> combinationSum(std::vector<int>& candidates, int target) {\n return BFS(candidates, target);\n }\n\nprivate:\n\nstd::vector<std::vector<int>> combinationSumDP(std::vector<int>& candidates, int targ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\n vector<vector<int>> solve(vector<int>& candidates, int target, int idx) {\n if (target == 0) {\n return {{}};\n }\n if (idx < 0 || target < 0) {\n return {};\n }\n \n vector<vector<int>> ans1 = solve(candidates, target, i...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\n void fun(vector<int>&nums, int i,int n,int target, vector<int>temp, vector<vector<int>>&ans){\n if(i==n && target!=0) return ;\n if(target==0) {ans.push_back(temp); return;}\n fun(nums,i+1,n,target,temp,ans);\n while(target>=nums[i]){\n temp.push...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> recursion(int i, int target, vector<int>& a, vector<int>& b) {\n vector<vector<int>> c;\n if (target == 0) {\n c.push_back(b);\n return c;\n }\n if (i == a.size() || target < 0) {\n return c;\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void solve(vector<vector<int>> &ans, vector<int> &arr, vector<int> curr, int sum, int i, int n, int target)\n {\n if(i==n)\n {\n if(sum == target) ans.push_back(curr);\n return;\n }\n int k = 1;\n solve(ans,arr,curr,...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void second(vector<int>& candidates ,int pointer, vector<vector<int>>&arr , \n int target , int sum , vector<int>second1){\n if(sum==target){\n arr.push_back(second1);\n return ;\n } \n if(pointer == candidates.size()){\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSum(vector<int>& nums, int target, int ind=0) {\n int n = nums.size();\n vector<vector<int>> ans;\n if(ind >= n)\n return ans;\n if(target == 0) {\n vector<int> temp;\n ans.push_back(t...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n\n\n\n vector<vector<int>> combinations;\n\n void helperCombinationSums(vector<int> candidates, int target, int curIndex, vector<int> curCombination, int curSum) {\n\n if(curIndex >= candidates.size()) return;\n \n int oldSum = curSum;\n vector<...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void fn(int i,vector<int>& candidates,vector<int> temp,vector<vector<int>>& res,int t)\n {\n if(t<0)\n return;\n if(t==0)\n {\n res.push_back(temp);\n return;\n }\n if(i==candidates.size())\n return;\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n sort(candidates.begin(), candidates.end());\n vector<vector<int>> out;\n vector<int> curr;\n\n int i = 0;\n while(i < candidates.size()){\n forwards(out, ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\nprivate:\n void combinations(vector<int> input, vector<int> current, vector<vector<int>>& res, int target, int sum = 0, int index = 0) {\n if(sum == target) {\n res.push_back(current);\n return;\n }\n if(sum > target) {\n return;\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void backtrack(int s, vector<vector<int>>& res, vector<int> comb, vector<int> arr, int t){\n if(t<0) return;\n if(t==0){\n res.push_back(comb);\n return;\n }\n for(int i=s;i<arr.size();i++){\n comb.push_back(arr[i])...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> res;\n set<vector<int>> check;\n void solve(vector<int> arr, int target, int n,vector<int> &path){\n\n if(target==0&&n==0){\n // if(check.find(path)==check.end())\n // {\n res.push_back(path);\n // check.insert(pat...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n vector<vector<int>> ans;\n //sort(candidates.begin(),candidates.end());\n vector<int> combination;\n\n findComb(candidates, ans,target, combination,0);\n return ans;...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void helper(vector<int> candidates, int target, int start, vector<int>& curr, vector<vector<int>>& res) {\n if (target < 0) return;\n if (target == 0) {\n res.push_back(curr);\n return;\n }\n for (int i = start; i < candidates...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n vector <vector <int> > ans;\n vector <int> cur;\n void rec(int target, vector <int> nums, int i) {\n if (target == 0) {\n ans.push_back(cur);\n return;\n }\n else if (target < 0) {\n return;\n }\n \n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\nvector<vector<int>> res;\n\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n helper(candidates,0,{},target,0);\n return res; \n }\n void helper(vector<int> candidates,int curr, vector<int> temp, int target, int sum) {\n if(sum...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n\n/*\nThe problem is to avoid repeating. 2 {7,6,3,2} and 3 {7,6,3,2} will both generate solutions 2,3.. and 3,2..\n\n[2,3,6,7], target = 7\n\n / | \\ \\\n 2{2,3,6,7} 3{3,6,7} 6{7} 7 #==> 2 branch includes every solution with including 2 including 22...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSum(vector<int>& can, int t) {\n vector<vector<int>>ans;\n vector<int>tem;\n recur(ans,can,t,tem);\n unordered_map<string,vector<int>>mp;\n for(int i=0;i<ans.size();i++){\n string str=\"\";\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSum(vector<int>& can, int t) {\n vector<vector<int>>ans;\n vector<int>tem;\n sort(can.begin(),can.end());\n recur(ans,can,t,tem);\n unordered_map<string,vector<int>>mp;\n for(int i=0;i<ans.size();i++){\n...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\n unordered_map<string, vector<vector<int>>> dp;\n\n vector<vector<int>> find(int ind, int target, vector<int>& cand) {\n // Base case: if the target is achieved, return a list containing an empty combination\n if (target == 0) return {{}};\n \n // If inde...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void f(int i,int tgt,vector<int>&arr,vector<int>&curr,vector<vector<int>>&st){\n if(i<0 || tgt <=0){\n if(tgt ==0 ){\n st.push_back(curr);\n }\n return;\n }\n f(i-1,tgt,arr,curr,st);\n if(arr[i]<=tgt){\...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n\n //Idea: Use backtracking to dfs a decision tree of candidates\n //Base Case: If the running sum of this branch == target, return (we found a combination)\n //Base Case: If adding this number pushes the running sum > target, return (terminate the branch)\n //Each ti...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n vector<vector<int>> res;\n\n function<void(int, vector<int>, int)> dfs = [&] (int i, vector<int> curr, int sum) {\n if(sum == target) {\n res.push_back(curr);\n...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n\n void solve(vector <int> &candidates,int target,int i,int curr,vector <int> &cv,vector <vector<int>> &ans){\n int n = candidates.size();\n if(i==n){\n if(target==curr){\n ans.push_back(cv);\n return;\n }\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n //candidates = candidates.sort();\n vector<vector<int>> result;\n\n stack<vector<int>> path;\n vector<int> first(candidates.size(), 0);\n for(int i = 0; i < first.si...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\nvector<vector<int>>ans;\n void findCombinationSum(vector<int>&arr,int target,int curr,vector<int>v)\n {\n if(target==0)\n {\n ans.push_back(v);\n return;\n }\n if(curr==arr.size())\n return;\n if(arr[curr]<=target)\n {\n v.pus...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void f(int i,int n,vector<int> &candidates,int target,vector<int> v,set<vector<int>> &s) {\n if(target==0) {\n s.insert(v); \n return ;\n }\n if(i>=n) return ; \n // if(candidates[i]>target) return ; \n f(i+1,n,candidat...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> ans;\n vector<int> temp;\n void recursion(vector<int>& candidates, int target,int currentIndex,string vis){\n cout<<vis<<endl;\n if(target == 0){\n ans.push_back(temp);\n return;\n }\n \n \n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void slv(vector<int>& candi, int target, vector<int> temp,\n set<vector<int>>&ans, int i){\n if(target == 0){\n sort(temp.begin(),temp.end());\n ans.insert(temp);\n return;\n }\n if(target < 0) return;\n if(i<0)...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "#define c candidates\nclass Solution {\npublic:\n void f(int target,vector<int> & vec, vector<vector<int>> & ans,vector<int>& candidates){\n if(target==0){\n ans.push_back(vec);\n }\n else{\n for(int i=0;i<c.size();i++){\n if(c[i]<=target){\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\nvoid f(vector<int>&nums,int ind,int target, vector<int>hello,vector<vector<int>>&ans)\n{\n if(ind>=nums.size())\n {\n if(target==0) ans.push_back(hello);\n return; \n }\n\n if(nums[ind]<=target)\n {\n hello.push_back(nums[ind]);\n f(nums...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void solver(int i, vector<int> &candidates, vector<vector<int>> &ans, int target, vector<int> v)\n {\n int n=candidates.size();\n \n if(target<0)\n return;\n if(i==n-1)\n {\n if(target%candidates[i]==0)\n {\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void f(int n,int tar,vector<int>sub,vector<int>& nums,vector<vector<int>>&ans)\n {\n if(tar==0)\n {ans.push_back(sub);return;}\n if(n==nums.size()-1)\n {\n if(tar%nums[n]==0)\n {\n int val=tar/nums[n];\n while(val--...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\nvoid f(int i,int j,int t,vector<int>& candidates,vector<vector<int>>&v,vector<int>v2){\n if(t<0 || i>=j){\n return;\n }\n if (t == 0) {\n if (std::find(v.begin(), v.end(), v2) == v.end()) {\n v.push_back(v2);\n }\n ...
39
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of </em><code>candidates</code><em> where the chosen numbers sum to </em><code>target</code><em>.</em> You may return the combinations i...
3
{ "code": "class Solution {\npublic:\n void helper(int i, int n, vector<int>& candidates, int target, int sum, vector<int> temp, vector<vector<int>>& ans){\n if(i == n){\n if(sum == target){\n ans.push_back(temp);\n return;\n }\n return;\n ...