id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 0 | {
"code": "class Solution {\npublic:\n bool contain(vector<int>& v){\n for(int i=0; i<v.size();i++){\n if(v[i]<0) return false;\n }\n return true;\n }\n string minWindow(string s, string t) {\n vector<int> v(150,0);\n for(int i=0;i<t.size();i++){\n v[... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 0 | {
"code": "class Solution {\nprivate: \n bool isEqual(vector<int> &source, vector<int> &target){\n for(int i=0; i<58; i++){\n if(target[i]!=0 and source[i]<target[i]) return false;\n }\n return true;\n }\npublic:\n string minWindow(string s, string t) {\n vector<int> ta... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 0 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n vector<int> freqT(128);\n for (char ch : t) {\n freqT[ch]++;\n }\n\n vector<int> freqS(128);\n int minLen = INT_MAX;\n int l = -1;\n int j = 0;\n\n for (int i = 0; i < ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 0 | {
"code": "class Solution {\npublic:\n \n string minWindow(string s, string t) {\n string ans=\"\";\n if (t.size() > s.size()) return \"\";\n vector<int> hash(256,0);\n int l =0;\n int r=0;\n int m = s.size();\n int n = t.size();\n int minl = 1e5;\n int cnt = 0;\n int si=-1;\... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 0 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n if (t.empty() || s.empty()) return \"\";\n \n vector<int> countT(128, 0), window(128, 0); \n for (char c : t) countT[c]++;\n \n int left = 0, minLength = INT_MAX, start = 0, matches = 0, requir... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n int n=s.size();\n int m=t.size();\n int minLen=INT_MAX,sIndex=-1,left=0,right=0,cnt=0;\n int hash[256]={0};\n for(int i=0;i<m;i++) hash[t[i]]++;\n while(right<n){\n if(hash[s[right]]... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n int n=s.length();\n int m= t.length();\n int minlen = INT_MAX;\n int cnt=0;\n int sindex=-1;\n int l=0;\n int r=0;\n int hash[256]={0};\n for(int i=0;i<m;i++){\n ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n int n1=s.size();\n int n2=t.size();\n int l=0;\n int r=0;\n int mini=1e9;\n int count=0;\n int start=-1;\n int mp[256]={0};\n for(int i=0;i<n2;i++){\n mp[t[i]]++... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n int need[128] = {0}; // Array to store the frequency of characters required from 't'\n int window[128] = {0}; // Array to store the frequency of characters in the current window\n int strLength = s.size(), targetLe... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\nbool isValid(vector<int> &tHash, vector<int> &sHash){\n for(int i=0;i<256;i++){\n // if(tHash[i]!=0) cout<<\" tHash[i] : \"<<tHash[i]<<\" , sHash[i] : \"<<sHash[i]<<endl;\n if(tHash[i]!=0 && tHash[i]>sHash[i]) return false;\n }\n return true;\n}\npublic:\n string... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\npublic:\n pair<int, int> best;\n string s;\n string t;\n int goal_hist[128] = {};\n int curr_hist[128] = {};\n int i = 0;\n int j = 0;\n\n bool hist_valid() {\n for (int i = 0; i < 128; i++) {\n if (curr_hist[i] < goal_hist[i]) {\n ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "#define maxn 100010\n#define count _count\n\nclass Solution {\npublic:\n int S[maxn], T[maxn], count[130], cur_count[130], is_full[130];\n int n, m;\n string minWindow(string s, string t) {\n n= s.length();\n m= t.length();\n for (int i=0; i<n; i++) S[i+1]= s[i]-'a'+60;\n ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\npublic:\n pair<int, int> best;\n string s;\n string t;\n int goal_hist[128] = {};\n int curr_hist[128] = {};\n int i = 0;\n int j = 0;\n\n bool hist_valid() {\n for (int i = 0; i < 128; i++) {\n if (curr_hist[i] < goal_hist[i]) {\n ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\nbool isValid(vector<int> &tHash, vector<int> &sHash){\n for(int i=0;i<256;i++){\n if(tHash[i]!=0 && tHash[i]>sHash[i]) return false;\n }\n return true;\n}\npublic:\n string minWindow(string s, string t) {\n int maxLen=INT_MAX;\n int maxStart=-1, maxEnd=-1;... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n if (s.length() < t.length()) {\n return \"\";\n }\n\n unordered_map<char, int> charCount;\n for (char ch : t) {\n charCount[ch]++;\n }\n\n int targetCharsRemaining = t.len... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n unordered_map<char, int> chars;\n for(char c: t){\n if(chars.find(c) == chars.end()) chars[c] = 0;\n chars[c] += 1;\n }\n\n int left = 0;\n int right = 0;\n int min_len = ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n unordered_map<char, int> chars;\n for(char c: t){\n if(chars.find(c) == chars.end()) chars[c] = 0;\n chars[c] += 1;\n }\n\n int left = 0;\n int right = 0;\n int min_len = ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n int n=s.length();\n int m=t.length();\n unordered_map<char,int>mp;\n for(int i=0;i<m;i++){\n mp[t[i]]++;\n }\n int l=0;\n int r=0;\n int cnt=0;\n int minlen=1e9;... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n int f = t.size();\n unordered_map<char, int> m;\n \n for (auto &ch : t) {\n m[ch]++;\n }\n \n int n = s.size();\n int i = 0;\n int j = 0;\n int start_indx... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\npublic:\n string minWindow(string str, string t) {\n int l=0,r=0,s=0,length=INT_MAX;\n int need=0,have=0;\n\n unordered_map<char,int> ref, substr;\n\n for (auto i: t) ref[i]++;\n need = ref.size();\n \n for (;r<str.length();r++){\n ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 1 | {
"code": "class Solution {\npublic:\n string minWindow(string str, string t) {\n int l=0,r=0,s=0,length=INT_MAX;\n int need=0,have=0;\n\n unordered_map<char,int> ref, substr;\n if (t.length() > str.length()) return \"\";\n\n for (auto i: t) ref[i]++;\n need = ref.size();\... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 2 | {
"code": "class Solution {\npublic:\n string minWindow(string str, string t) {\n int l=0,r=0,s=0,length=INT_MAX;\n int need=0,have=0;\n\n unordered_map<char,int> ref, substr;\n if (str == t) return t;\n if (t.length() > str.length()) return \"\";\n\n for (auto i: t) ref[i... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 2 | {
"code": "class Solution {\npublic:\n string minWindow(string str, string t) {\n int l=0,r=0,s=0,length=INT_MAX;\n int need=0,have=0;\n\n unordered_map<char,int> ref, substr;\n if (str == t) return t;\n if (t.length() > str.length()) return \"\";\n\n for (auto i: t) ref[i... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 2 | {
"code": "class Solution {\npublic:\n string minWindow(string str, string t) {\n int l=0,r=0,s=0,length=INT_MAX;\n int need=0,have=0;\n\n unordered_map<char,int> ref, substr;\n\n for (auto i: t) ref[i]++;\n need = ref.size();\n \n for (;r<str.length();r++){\n ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 2 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n if(s.empty()||t.empty()){\n return \"\";\n }\n unordered_map<char,int>required;\n for(char c : t){\n required[c]++;\n }\n int requiredCount = required.size();\n\n i... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n int m = s.length();\n int n = t.length();\n int e = 0;\n int itne = 0;\n unordered_map<char, int> mp, cnt;\n for (auto &ch: t) mp[ch]++;\n for (; e < m; e++) {\n cnt[s[e]]++;\... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n bool containsAllChars(unordered_map<char, int>& mpT,\n unordered_map<char, int>& mpS) {\n for (auto entry : mpT) {\n if (mpS.find(entry.first) == mpS.end() ||\n mpS[entry.first] < entry.second)\n return ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n unordered_map<char, int> charCnt;\n int num = 0;\n\n for(auto c : t){\n if(charCnt.find(c) == charCnt.end()) num++;\n charCnt[c]++;\n }\n\n int n = s.length();\n int l = 0... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n int n=s.length();\n if(s.length()<t.length())return \"\";\n int i=0, j=0;\n string ans=\"\";\n int len=n;\n unordered_map<char,int>mp;\n for(auto it : t){\n mp[it]++;\n }\n int k=t.le... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n if (t.length() == 0) return \"\";\n map < char, int > mpt;\n map < char, int > mps;\n for (int i = 0; i < t.length(); i++) {\n mpt[t[i]]++;\n }\n int cur = 0, total = mpt.size();\n int i = 0, j = 0;\n int res = INT_MAX... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n unordered_map<char, long long> fT;\n unordered_map<char, long long> sT;\n\n for (auto& x : t)\n fT[x]++;\n string ans = \"\";\n int i = 0;\n int j = 0;\n int cnt = 0;\n ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n string findMinStr(string& s,string& t,unordered_map<char,int> tmap){\n int start=0;\n int tRemaining=t.size();\n string ans = \"\";\n int minWind[2]={0,INT_MAX};\n for(int end=0;end<s.size();end++){\n char ch=s[end];\n ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n const int m = s.size();\n const int n = t.size();\n\n if (m < n)\n return \"\";\n\n map<char, int> letterCnt;\n map<char, int> currentLetterCnt;\n\n for (const char c : t) {\n ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n string minWindow(string S, string T) {\n string result;\n if(S.empty() || T.empty()){\n return result;\n }\n unordered_map<char, int> map;\n unordered_map<char, int> window;\n for(int i = 0; i < T.length(); i++){\n map[T[i]]++;\n }\n int ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n int ls = s.size(), lt = t.size();\n map<char, int> my;\n for(char ch : t) my[ch]++;\n int i = 0;\n string res = \"\";\n for(int j=0; j<=ls; j++) {\n char ch = s[j];\n if(m... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<char, int> getCount(string s) {\n unordered_map<char, int> result;\n for (char c : s) {\n result[c]++;\n }\n return result;\n }\n\n bool isContain(unordered_map<char, int> s, unordered_map<char, int>& t) {\n fo... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n\n string minWindow(string s, string t) {\n // brute force: s[i:j] O(n^2) TLE\n // prefix: if we can encoding char counts, c[i:j] = c[j] - c[i] == c_t, we can find c[j] - c_t in previous set, get index i, then get min(j - i)\n \n // BS! do not has, ... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n bool isContained(unordered_map<char, int>& smap, unordered_map<char, int>& tmap) {\n for (auto& e: tmap) {\n if (smap.find(e.first) != smap.end()) {\n //cout << \"Char: \" << e.first << \", \" << smap[e.first] << \", \" << tmap[e.first] << end... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n int n=s.length();\n map<char,int>map_t_str;\n for(auto it:t)\n map_t_str[it]++;\n \n string res=\"\";\n if(t.length()==1){\n for(auto it:s){\n if(it==t[0]){... |
76 | <p>Given two strings <code>s</code> and <code>t</code> of lengths <code>m</code> and <code>n</code> respectively, return <em>the <strong>minimum window</strong></em> <span data-keyword="substring-nonempty"><strong><em>substring</em></strong></span><em> of </em><code>s</code><em> such that every character in </em><code>... | 3 | {
"code": "class Solution {\npublic:\n\n bool contains(map<char, int>& MS, map<char, int>& MT) {\n\n for(auto x : MT) {\n\n if(MS[x.first] < x.second)\n return false;\n }\n return true;\n }\n\n string minWindow(string s, string t) {\n \n map<char, ... |
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>
<... | 0 | {
"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{\npublic:\n std::vector<std::vector<int>> combine(const 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>
<... | 0 | {
"code": "class Solution {\npublic:\n void combinationgenerator(vector<vector<int>> &res, vector<int> &subarr, int n, int k, int i, int layer, int &resind)\n {\n if (layer > k)\n {\n res[resind++] = subarr;\n }\n else\n {\n for (int j = i; j <= n; 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>
<... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<vector<int>> ans;\n ans.reserve(n * k);\n\n vector<int> cur;\n cur.reserve(k);\n backtrack(1, n, k, cur, ans);\n return ans;\n }\n\nprivate:\n void backtrack(int i, int n, 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>
<... | 0 | {
"code": "class Solution {\npublic:\n\tvector<vector<int>> combine(int n, int k) {\n\t\tvector<vector<int>> result;\n\t\tint i = 0;\n\t\tvector<int> p(k, 0);\n\t\twhile (i >= 0) {\n\t\t\tp[i]++;\n\t\t\tif (p[i] > n) --i;\n\t\t\telse if (i == k - 1) result.push_back(p);\n\t\t\telse {\n\t\t\t ++i;\n\t\t\t p[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>
<... | 0 | {
"code": "class Solution {\npublic:\n void comb(int ind,vector<int>& arr,int k,vector<int>& ds,vector<vector<int>>& ans)\n { if(ind>=arr.size())\n {\n if(k==0)\n {\n ans.push_back(ds);\n \n }\n return;\n }\n \n ds.push_back(arr[ind]... |
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>
<... | 0 | {
"code": "class Solution {\npublic:\n void helper(int i, int n, int k, int idx, vector<int> ¤t, vector<vector<int>> &res) {\n if(idx == k) {\n res.push_back(current);\n return;\n }\n if(i > n) {\n return;\n }\n \n current[idx++] = 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>
<... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n std::vector<std::vector<int>> res;\n std::vector<int> comb;\n\n backtrack(1, comb, res, n, k);\n return res; \n }\n\nprivate:\n void backtrack(int start, std::vector<int>& comb, std::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>
<... | 0 | {
"code": "class Solution {\npublic:\n void backtrack(vector<vector<int>> &result, vector<int> &temp, int start, int n, int k) {\n if (temp.size() == k) {\n result.push_back(temp);\n return;\n }\n for (int i = start; i <= n; i++) {\n temp.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>
<... | 1 | {
"code": "struct Combination {\n int n;\n int k;\n list<int> combination;\n\n Combination(int n, int k) : n(n), k(k) {\n for(int i=1; i<=k; i++) {\n combination.push_back(i);\n }\n }\n\n vector<int> getCombination() {\n return vector<int>(combination.begin(), 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>
<... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n long long int total = 1;\n for (int i = 0; i < k; ++i)\n {\n total *= (n-i);\n }\n for (int i = 0; i < k; ++i)\n {\n total /= (k-i);\n }\n answer = std:... |
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>
<... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n answer = std::vector<std::vector<int>>(GetNumCombine(n, k), std::vector<int>(k));\n index = 0;\n\n N = n;\n K = k;\n\n combine_rec(1, k);\n return answer;\n }\n\nprivate:\n void comb... |
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>
<... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n long long int total = 1;\n for (int i = 0; i < k; ++i)\n {\n total *= (n-i);\n }\n for (int i = 0; i < k; ++i)\n {\n total /= (k-i);\n }\n answer = std:... |
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>
<... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n int total = 1;\n for (int i = 0; i < k; ++i)\n {\n total *= (n-i);\n total /= (i+1);\n }\n \n answer = std::vector<std::vector<int>>(total, std::vector<int>(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>
<... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n int total = 1;\n for (int i = 0; i < k; ++i)\n {\n total *= (n-i);\n total /= (i+1);\n }\n \n answer = std::vector<std::vector<int>>(total, std::vector<int>(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>
<... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n // dfs\n N = n;\n K = k;\n long long nCr = 1;\n {\n int cnt = 0;\n while (cnt < k && n > 1) {\n nCr *= n--; ++cnt;\n }\n while (k > 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>
<... | 1 | {
"code": "class Solution {\nprivate:\n int nCk(int n, int k) {\n int ans = 1;\n int i;\n\n for (i = 1; k; --k, ++i) {\n ans = ans * n / i;\n --n;\n }\n\n return ans;\n }\n\npublic:\n vector<vector<int>> ans;\n vector<int> curr;\n\n void dfs(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>
<... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> answer;\n vector<int> path;\n int k;\n int n;\n\n void doPath(int current_minimal_value){\n // 1. put values\n\n for (int current_value = current_minimal_value; current_value <= n; current_value++){\n path.push_back(cur... |
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>
<... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<vector<int>>ans;\n vector<int>temp;\n f(ans,temp,1,n,k);\n return ans;\n\n }\n void f(vector<vector<int>>&ans, vector<int>&temp,int i, int n,int k){\n if(temp.size()==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>
<... | 1 | {
"code": "\nclass Solution {\npublic:\n void helper(vector<vector<int>>& ans, int n, int k, vector<int>& curr, vector<bool>& flag , int prev ) {\n if (k == 0) {\n vector<int> nC = curr;\n ans.push_back(nC);\n return;\n }\n\n\n for(int i = prev + 1; i <= n ; 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>
<... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n // dfs\n N = n;\n K = k;\n vector<int> temp;\n ans.reserve(n * n-1);\n temp.reserve(K);\n dfs(temp, 0);\n return ans;\n }\n int N, K;\n vector<vector<int>> ans;\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>
<... | 1 | {
"code": "class Solution {\npublic:\n void func(vector<int>& num, int k, int i, vector<vector<int>>& ans,\n vector<int>& tp) {\n if (tp.size() == k) {\n ans.push_back(tp);\n return;\n }\n if(num.size()-i+tp.size()<k){\n return;\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>
<... | 1 | {
"code": "class Solution {\nprivate:\n std::vector<vector<int>> retVal;\n void solve(vector<int>& nums, int k, int index, std::vector<int>& sol) {\n if(sol.size() == k) {\n retVal.push_back(sol);\n return;\n }\n for(int i=index; i<nums.size(); i++){\n sol.p... |
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>
<... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> fAns;\n void findCombination(vector<int> &v,int r,vector<int> &curAns,int idx){\n if(curAns.size()==r){\n fAns.push_back(curAns);\n return;\n }\n for(int i=idx;i<v.size();i++){\n curAns.push_back(v[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>
<... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<vector<int>> res;\n vector<int> prev;\n GenerateCombination(1, n, k, &prev, &res);\n return res;\n }\n void GenerateCombination(int start, int end, int k, vector<int>* prev, vector<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>
<... | 2 | {
"code": "class Solution {\npublic:\n \n void Myfun(int idx, int k, vector<int> &temp, vector<vector<int> >&ans, int n){\n \n if(temp.size()==k){\n ans.push_back(temp);\n return;\n }\n \n if(idx>n)\n return;\n \n temp.push_back(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>
<... | 2 | {
"code": "class Solution {\npublic:\n void combinations(int n,int k,vector<vector<int>> &ans,vector<int>&temp,int index){\n \n if(temp.size()==k){\n ans.push_back(temp);\n return;\n}\n if(index>n)\n return;\n //exclude\n combinations(n,k,ans,temp,index+1);\n // include\n temp.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>
<... | 2 | {
"code": "class Solution {\npublic:\n void solve(int idx, vector<int>&nums, vector<int>& temp, vector<vector<int>>& ans,unordered_set<int>& st, int k)\n {\n if(k == 0)\n {\n ans.push_back(temp);\n return;\n }\n if(idx == nums.size()) return;\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>
<... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<vector<int>> result;\n\n combiner(n, k, 1, vector<int>(k, 0), result);\n\n return result;\n }\n\n void combiner(int n, int k, int beginNum, vector<int> combineSet, vector<vector<int>>& result){\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>
<... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<vector<int>> res;\n vector<int> out;\n vector<int> nums;\n unordered_set<int> check;\n for(int i=1;i<=n;i++){\n nums.push_back(i);\n }\n combinations(0,nums,out,ch... |
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>
<... | 2 | {
"code": "class Solution {\npublic:\n set<vector<int>> ans;\n vector<int> path;\n vector<vector<int>> combine(int n, int k) {\n solve(1, n, k);\n return vector(ans.begin(), ans.end());\n }\n void solve(int start, int n, int k){\n if(path.size() == k){\n ans.insert(path)... |
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>
<... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n // bit-brute-force \n set<vector<int>> ans;\n vector<int> temp;\n temp.reserve(k);\n for (int i = 0; i < pow(2, n); ++i) {\n if (popcount(static_cast<uint32_t>(i)) != k) continue;\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>
<... | 2 | {
"code": "class Solution {\npublic:\n void solve(int ind,int n,int k,vector<int>sol,vector<vector<int>>& ans){\n if(k==1){\n for(int i=ind;i<=n;i++){\n sol.push_back(i);\n ans.push_back(sol);\n sol.pop_back();\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>
<... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n int l = -1;\n vector<vector<int>> ans;\n for(int i = 0; i < (1<<n); i++){\n\n int ct = 0;\n for(int j = 0; j < n; j++) if(i>>j&1) ct++;\n \n if(ct == 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>
<... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n int M = 1 << n;\n\n vector<vector<int>> result;\n\n vector<int> current;\n current.reserve(k);\n\n for (int i = 0; i < M; ++i) {\n if (hamming(i) != k) continue;\n\n for (int j = 0; j < n; ++j) {\n if... |
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>
<... | 2 | {
"code": "class Solution {\npublic:\nvoid solve(vector<vector<int>>& ans, vector<int> &temp, int currIndex,int k,vector<int>&temp2){\n\n if(currIndex>=temp.size() || k==0) {\n if(k==0)\n ans.push_back(temp2);\n return ;\n }\n\n solve(ans,temp,currIndex+1,k,temp2);\n temp2.push_back(t... |
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>
<... | 2 | {
"code": "class Solution {\npublic:\nvoid solve(vector<vector<int>>& ans, vector<int> &temp, int currIndex,int k,vector<int>&temp2){\n\n if(currIndex>=temp.size() || k==0) {\n if(k==0)\n ans.push_back(temp2);\n return ;\n }\n\n solve(ans,temp,currIndex+1,k,temp2);\n temp2.push_back(t... |
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>
<... | 2 | {
"code": "class Solution {\npublic:\n\n\n void combinations(int ind,int n,int k,vector<int> &ds,vector<vector<int>> &ans){\n if(ind>n){\n if(ds.size()==k)\n ans.push_back(ds);\n return ; \n }\n\n ds.push_back(ind);\n combinations(ind+1,n,k,ds,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>
<... | 2 | {
"code": "class Solution {\n private:\n void getCombinations(int i,int& n,int k,vector<vector<int>>& ans,vector<int>& temp){\n if(i>n){\n if(k==0){\n ans.push_back(temp);\n }\n return;\n }\n temp.push_back(i);\n getCombinations(i+1,n,k-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>
<... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<vector<int>> sol;\n if(k == 1){\n for (int i = 1; i <= n; i++){\n sol.push_back({i});\n }\n }\n else {\n vector<int> cur;\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>
<... | 2 | {
"code": "class Solution {\nprivate:\n void backtrack(int n, int k, int start, vector<int> comb, vector<vector<int>> &res) {\n if (comb.size() == k) {\n res.push_back(comb);\n return;\n }\n\n for (int num = start; num <= start + ((n - start + 1) - (k - comb.size())); num... |
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>
<... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<vector<int>> res;\n vector<int> curr;\n unordered_set<int> used;\n\n backtrack(res, curr, used, n, k, 1);\n return res;\n }\n\n void backtrack(vector<vector<int>>& res, vector<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>
<... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<vector<int>> ans;\n unordered_set<int> seen;\n vector<int> currAns;\n findAllCombinations(n, k, 1, seen, currAns, ans);\n return ans;\n }\n void findAllCombinations(int n, int k, 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>
<... | 2 | {
"code": "class Solution {\npublic:\n void dfs(int index, set<vector<int>>& ans, vector<int>& a, int k, int n) {\n if (a.size() == k) {\n sort(a.begin(), a.end());\n ans.insert(a);\n return;\n }\n \n for (int i = index; i <= n; i++) {\n a.p... |
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>
<... | 2 | {
"code": "class Solution {\npublic:\n void combine(vector<vector<int>>& combinations, vector<int> combination, int n, int k, int start) {\n if(n - start + 1 < k) {\n return;\n }\n \n if(k == 0) {\n combinations.push_back(combination);\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>
<... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) \n {\n vector<vector<int>> ans;\n for(int b=0;b<(1<<n);b++)\n {\n vector<int> temp;\n if(__builtin_popcount(b)!=k) continue; \n for(int i=0;i<n;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>
<... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n vector<vector<int>> ans;\n for(int i=0; i<(1 << n); i++){\n int s = __builtin_popcount(i);\n if(s != k) continue;\n vector<int> tmp;\n for(int j=0; j<n; 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>
<... | 2 | {
"code": "class Solution {\npublic:\n void f(int ind, int n, int k, vector<int> curset, vector<vector<int>> &res){\n //a\n if(k==0){\n res.push_back(curset);\n return;\n }\n //b\n if(ind>n){\n return;\n }\n //c\n //pruning - ... |
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(1);\n for (int i = 1; i <= n; ++i ) {\n int stop = result.size();\n int p = 0, cutoff = i+k-n-1;\n for (int j = 0; j < stop; ++j) {\n int 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": "#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": "#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": "#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 void allComb(vector<int> &nums, int s, int k, vector<int> temp, vector<vector<int>> &res){\n int n = nums.size();\n if(k==0){\n res.push_back(temp);\n return;\n }\n for(int i = s; i < n; i++){\n if(n-i+1<k) return;\... |
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 vectorPopFront(std::vector<int>& vec) {\n\tfor (int i = 1; i < vec.size(); i++) vec[i - 1] = vec[i];\n\tvec.resize(vec.size()-1);\n}\n\nvoid combineBacktrackung(std::vector<std::vector<int>>& res, std::vector<int> subRes, std::vector<int> range, int k) {\n\tif (range.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 vector<vector<int>> combine(int n, int k) {\n auto allComp = allCombines(n, k, k);\n return allComp;\n }\n\nprivate:\n vector<vector<int>> allCombines(int k, int maxN, int n)\n {\n vector<vector<int>> result;\n if (n == 1)\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 {\npublic:\n vector<vector<int>> combine(int n, int k) {\n pattern = vector<int>(k, 0);\n auto allComp = allCombines(n, k, k);\n return allComp;\n }\n\nprivate:\n vector<int> pattern;\n vector<vector<int>> allCombines(int k, int maxN, int n)\n {\n v... |
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;\nint m;\n void f(int ind,vector<int>&arr,int k,vector<int>&vec)\n {\n //bc\n if(ind>=m)\n {\n if(vec.size()==k)\n res.push_back(vec);\n return ;\n }\n f(ind+1,arr,k,vec);\n vec.push_back(arr[ind]);\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 set<vector<int>>st;\n void printvec(vector<int>vc){\n for(int i=0;i<vc.size();i++){\n cout<<vc[i]<<\" \";\n }\n cout<<endl;\n }\n void findans(int n,int start,int k,vector<int>&vt){\n // printvec(vt);\n if(vt.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>> ans;\n vector<int> comb;\n int n;\n\n void solve(int k, int cur) {\n if (cur > n) {\n if (!k)\n ans.push_back(comb);\n return;\n }\n\n // Pick cur\n comb.push_back(cur);\n sol... |
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 std::vector<vector<int>> retVal;\n void solve(int n, int k, int index, std::vector<int>& sol) {\n if(index > n) {\n if(sol.size()==k)\n retVal.push_back(sol);\n return;\n }\n sol.push_back(index);\n if(sol.s... |
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 void p(int n, int k, int i, int j, vector<int> arry) {\n if (i == k) {\n res.push_back(arry);\n return;\n }\n\n while (j <= n) {\n arry[i]=j;\n p(n, k, i + 1,j + 1, arry);\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.