id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n set<char> s ;\n for (int i=0;i<allowed.length();i++) {\n s.insert(allowed[i]);\n }\n int value = s.size();\n int count = 0 ;\n for (int i=0;i<words.size(...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string &allowed, vector<string>& words) {\n int ans;\n for (int i = 0; i < 2500; ++i) {\n ans = countConsistentStrings1(allowed, words);\n }\n return ans;\n }\n\n int countConsistentStrings1(string allowe...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string &allowed, vector<string>& words) {\n int ans;\n for (int i = 0; i < 2600; ++i) {\n ans = countConsistentStrings1(allowed, words);\n }\n return ans;\n }\n\n int countConsistentStrings1(string allowe...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string a, vector<string>& w) {\n unordered_map<char,int> mp;\n for(auto &i:a){\n mp[i]++;\n }\n unordered_map<char,int> mp1=mp;\n int k=mp.size();\n int z=0;\n for(int i=0;i<w.size();i++){\...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string &allowed, vector<string>& words) {\n int ans;\n for (int i = 0; i < 2600; ++i) {\n ans = countConsistentStrings1(allowed, words);\n }\n return ans;\n }\n\n int countConsistentStrings1(string allowe...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n bool detect(string s,string allowed)\n {\n int arr[30] = {0};\n for(int i = 0; i < allowed.size(); i++)\n arr[allowed[i] - 'a']++;\n\n for(int i = 0; i < s.size(); i++)\n {\n if(arr[ s[i] - 'a'] == 0)\n retur...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n \n bool isConsistent(string allowed,string s)\n {\n int freq[26] = {};\n for(int i=0;i<allowed.size();i++)\n freq[allowed[i]-'a']++;\n \n for(auto i:s)\n {\n if(!freq[i-'a'])\n return false;\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n bool isconsistent(string a,string b){\n int arr[26]={0};\n for(int i=0;i<b.size();i++){\n int x = b[i]-'a';\n arr[x]++;\n }\n for(int i=0;i<a.size();i++){\n if(arr[a[i]-'a']==0) {\n return false;\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n bool detect(string s,string allowed)\n {\n int arr[30] = {0};\n for(int i = 0; i < allowed.size(); i++)\n arr[allowed[i] - 'a']++;\n\n for(int i = 0; i < s.size(); i++)\n {\n if(arr[ s[i] - 'a'] == 0)\n retur...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n bool alllowed(string &str, string allowed)\n {\n int hash[26]={0};\n for (char ch : allowed) {\n hash[ch - 'a'] = 1;\n }\n for(int i=0;i<str.size();i++)\n {\n if(hash[str[i]-'a']==0)\n return false;\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\nstring removeCharAt(string str, int index) { \n string modifiedStr = str;\n modifiedStr.erase(index, 1);\n return modifiedStr;\n}\nbool equal(string test,string allowed) {\n for(int j = 0; j < allowed.size(); j++) {\n for(int i = 0; i < test.size(); i++) {\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n vector<int> freq(26, 0);\n vector<string> inConsistent;\n for(auto x:allowed) freq[x-'a']++;\n\n int ans = 0;\n for(auto word:words) {\n for(auto ch:word) {\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int count = 0;\n\n for (int i = 0; i < words.size(); i++) {\n removeAllowedCharacter(words[i], allowed);\n if (isConsistent(words[i], allowed)) count++;\n }\n\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int count = 0;\n\n for (int i = 0; i < words.size(); i++) {\n removeAllowedCharacter(words[i], allowed);\n if (isConsistent(words[i], allowed)) count++;\n }\n\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n\n int check(string a, string b){\n int n = a.size();\n int m = b.size();\n for(int i = 0;i < m;i++){\n int key = 0;\n for(int j = 0;j < n;j++){\n if(b[i] == a[j])\n key++;\n }\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int count = 0;\n\n for (int i = 0; i < words.size(); i++) {\n removeAllowedCharacter(words[i], allowed);\n if (isConsistent(words[i], allowed)) count++;\n }\n\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string a, vector<string>& words) {\n int v[1000000]={0};\n for(int i=0;i<a.length();i++){\n v[a[i]-'0']++;\n }\n int cnt=0;\n for(int i=0;i<words.size();i++){\n int l=words[i].length();int m=0...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string> words) {\n int contadorPalabrasConAllowed = 0;\n for(int posicionWords = 0; posicionWords < words.size(); posicionWords++){\n int posicionAllowed = 0;\n int letrasAllowed = 0;\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int wLen = words.size();\n if(wLen < 1 || wLen > 10000){\n return 0;\n }\n int aLen = allowed.length();\n if( aLen <1 || aLen > 26){\n return 0;\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n vector<string>v;\n v=words;int flag=0,count=0;\n for(int i=0;i<v.size();i++){\n string s=v[i];\n for(int j=0;j<s.length();j++){\n char s1=s[j];\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n bool check(string toCheck, vector<bool> allowedVec){\n for(int i=0; i<toCheck.size(); i++){\n if(allowedVec[toCheck[i]-'a'] == false){\n return false;\n }\n }\n return true;\n }\n int countConsistentStrings(stri...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\n bool check(const vector<bool>&v1,const vector<bool>&v2){\n for(int i = 0;i<26;i++){\n if(v2[i] == true && v1[i] == false)\n return false;\n }\n return true;\n }\npublic:\n int countConsistentStrings(string allowed, vector<string>& w...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n bool func(string& s,vector<bool> v)\n {\n for(auto& it: s)\n if(!v[it-'a']) return false;\n return true;\n }\n int countConsistentStrings(string allowed, vector<string>& words) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\n bool test(string word, vector<bool> allowed) {\n for (char c : word) if (!allowed[c - 'a']) return false;\n return true;\n }\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n ios_base::sync_with_stdio(false);\n vector<bo...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n stack<string> check;\n \n // Push all words into the stack\n for (int i = 0; i < words.size(); i++) {\n check.push(words[i]);\n }\n \n int count =...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n stack<string> check;\n \n // Push all words into the stack\n for (int i = 0; i < words.size(); i++) {\n check.push(words[i]);\n }\n \n int count =...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n map<int,int> mapp;\n int hash=0;\n for(auto &c:allowed){\n int x=c-'a';\n hash+=(1<<x);\n }\n for(auto & word : words){\n int cnt=0;\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n bool isPresent(string& str1,string &str2,vector<bool> &freq1){\n\n vector<bool> freq2(26,0);\n\n for(int i=0;i<str1.size();i++){\n freq2[str1[i]-'a']=true;\n }\n\n for(int i=0;i<26;i++){\n if(freq1[i]==0 && freq2[i]==1){\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n void counter(const string &src,vector<bool>& map)\n {\n for(char c:src)\n {\n map[c-'a'] = 1;\n }\n }\n\n bool cmp(const string &src,const vector<bool>& map)\n {\n vector<bool> str_map(26,0);\n for(char c:src)\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n bool isConsistent(string& allowedSet, string& word) {\n vector<bool> allowed(26, false);\n \n for (char c : allowedSet) {\n allowed[c - 'a'] = true;\n }\n\n for (char c : word) {\n if (!allowed[c - 'a']) {\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int getIndex(char &ch) {\n return ch - 'a';\n }\n void fillChars(string &allowed, vector<bool> &chars) {\n for(char &ch : allowed) {\n chars[getIndex(ch)] = true;\n }\n }\n bool isConsistent(string &word, vector<bool> &chars) {\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n void counter(string &src,vector<bool>& map)\n {\n for(char c:src)\n {\n map[c-'a'] = 1;\n }\n }\n\n bool cmp(string &src,vector<bool>& map)\n {\n vector<bool> str_map(26,0);\n for(char c:src)\n {\n if...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n void counter(const string &src,vector<bool>& map)\n {\n for(char c:src)\n {\n map[c-'a'] = 1;\n }\n }\n\n bool cmp(const string &src,const vector<bool>& map)\n {\n vector<bool> str_map(26,0);\n for(char c:src)\n ...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\n bool check(vector<bool> &mp, string &s)\n {\n vector<bool> freq(26, false);\n for(auto ch : s)\n {\n freq[ch-'a'] = true;\n }\n for(int i = 0;i < 26;++i)\n {\n if(!mp[i] && freq[i])\n {\n retu...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int ans=0;\n set<int>st;\n for(int i=0;i<allowed.length();i++){\n st.insert(allowed[i]);\n }\n vector<set<int>>v(words.size());\n for(int i=0;i<words.siz...
1,786
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return<em> the number of <strong>consistent</strong> st...
3
{ "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector<string>& words) {\n int cnt = 0;\n map<char, int> mp;\n for (auto i : allowed) {\n mp[i]++;\n }\n for (int i = 0; i < words.size(); i++) {\n for (auto j : words[i]) {\n ...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
0
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n = nums.size();\n std::vector<int> differenceArray(n);\n int leftSum = 0;\n int rightSum = 0;\n\n // Calculate the total sum of the array\n for (int num : nums) {\n ...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
0
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n = nums.size();\n vector<int> ans(n, 0);\n\n int prefixSum = 0, suffixSum = 0;\n for (int num : nums) {\n suffixSum += num;\n }\n\n for (int i = 0; i < n; ++...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
0
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n = (int)nums.size();\n vector<int> res(n);\n \n int prefix = 0, suffix = accumulate(nums.begin(), nums.end(), 0ll);\n\n for(int i = 0; i < n; i++) {\n res[i] = -pre...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
0
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n = nums.size();\n vector<int> ret(n, 0);\n for(int i = 1; i < n; i++){\n ret[0] += nums[i] - nums[0];\n }\n for(int i = 1; i < n; i++){\n ret[i] = ret[i-...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
0
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n=nums.size();\n vector<int> ans(n,0);\n int c=0;\n // cout<<temp[0]<<\" \";\n int sum=accumulate(nums.begin(),nums.end(),0);\n for(int i=0;i<n;i++)\n {\n ...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
0
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) \n {\n /*int n = nums.size(), tmp = 0;\n \n vector<int> ans(n);\n \n for(int i=0; i<n; i++)\n {\n tmp = 0;\n \n for(int j=0; j<n; j++)\n ...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
1
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n=nums.size();\n vector<int>result(n,0);\n vector<int>prefixSum(n,0);\n prefixSum[0]=nums[0];\n for(int i=1;i<n;i++){\n prefixSum[i]=prefixSum[i-1]+nums[i];\n ...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
1
{ "code": "class Solution {\npublic:\n std::vector<int> getSumAbsoluteDifferences(std::vector<int>& nums) {\n int n = nums.size();\n std::vector<int> result(n, 0);\n std::vector<int> prefix_sum(n + 1, 0);\n\n // Compute the prefix sum array\n for (int i = 1; i <= n; ++i) {\n ...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
1
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n vector<int> result(n,0);\n int total=accumulate(nums.begin(),nums.end(),0);\n vector<int> prefix(n,0);\n prefix[0]=nums...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
1
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n // [1, 4, 6, 8, 10]\n // 24 x x x x\n // 24 15 x x x\n // 24 15 13 x x\n // 24 15 13 15 x\n // 24 15 13 15 12\n\n // [1,4,6,8,10]\n // sum = 29\...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
1
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int total = 0;\n for (int i : nums) {\n total += i;\n }\n int acc = 0;\n vector<int> res;\n for (int i = 0; i < nums.size(); i++) {\n int lhs = nums[i]...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
1
{ "code": "#define ll long long\nclass Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) \n {\n ll sum=0;\n vector<int>v;\n\n for(auto it:nums)\n {\n sum+=it;\n }\n ll len=nums.size();\n ll temp=0;\n for(int i=0;i<le...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
1
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n vector<int> ans;\n int sum=0;\n int curr=0;\n int n=nums.size();\n for(int i=0;i<n;i++){\n sum+=nums[i];\n }\n for(int i=0;i<n;i++){\n curr+=num...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
1
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int sum = 0, sum_reverse = 0;\n for(int i = nums.size() - 1; i >= 0; i--) sum_reverse += nums[i];\n vector<int>res;\n int n = nums.size();\n for(int i = 0; i < nums.size(); i++){\n...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
1
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int sum = 0, sum_reverse = 0;\n for(int i = nums.size() - 1; i >= 0; i--) sum_reverse += nums[i];\n vector<int>res;\n int n = nums.size();\n for(int i = 0; i < nums.size(); i++){\n...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
1
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n vector<int> res;\n long long sum = 0;\n int n = nums.size();\n\n for(auto num : nums) {\n sum += num;\n }\n\n res.push_back(sum - nums[0] * n);\n\n for(int...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
2
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);\n vector<int>ans;\n int sum=0,cur=0,n=nums.size(),i;\n for(auto &it:nums)\n sum+=it;\n for(i=0;i<n;i++){\n ...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
2
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n = nums.size();\n vector<int> pref(n), suf(n);\n for(int i = 0; i < n; i++){\n pref[i] = (i == 0)? nums[i] : pref[i-1] + nums[i];\n }\n for(int i = n - 1 ; i >= 0; ...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
2
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int arr[nums.size()];\n vector<int> ans;\n arr[0] = nums[0];\n cout<<arr[0]<<\" \";\n for(int i = 1; i < nums.size(); ++i){\n arr[i] = arr[i-1] + nums[i];\n c...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
2
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int arr[nums.size()];\n vector<int> ans;\n arr[0] = nums[0];\n int l = nums.size();\n for(int i = 1; i < l; ++i){\n arr[i] = arr[i-1] + nums[i];\n }\n int ...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
2
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& a) {\n int n= a.size();\n vector<int> ans(n);\n vector<int> prefix(n);\n vector<int> suffix(n);\n prefix[0]=a[0];\n for(int i=1;i<a.size();i++){\n prefix[i]=prefix[i-1...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
3
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n = nums.size();\n vector<int> prefix(n,0);\n vector<int> suffix(n,0);\n prefix[0] = nums[0];\n suffix[n-1] = nums[n-1];\n for(int i=1;i<n;i++){\n prefix[i] =...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
3
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n=nums.size();\n vector<int > ans;\n int pre[n];\n int suf[n];\n pre[0]=0;\n suf[n-1]=0;\n \n for(int i=1;i<n;i++){\n pre[i]=pre[i-1]+nums[i-1]...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
3
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n=nums.size();\n int pre[n+1],suf[n+1];\n vector<int>ans;\n pre[0]=nums[0];\n suf[n-1]=nums[n-1];\n for(int i=1;i<n;i++){\n pre[i]=pre[i-1]+nums[i];\n ...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
3
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n = nums.size();\n vector<int> suf(nums.size());\n\n suf[n-1] = nums[n-1];\n for(int i = nums.size()-2; i >= 0; i--){\n suf[i] = suf[i+1] + nums[i];\n }\n\n i...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
3
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n = nums.size();\n vector<int> prefix(nums);\n vector<int> ans;\n prefix[0] = nums[0];\n for (int i = 1; i < n; i++) {\n prefix[i] += prefix[i - 1];\n }\n ...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
3
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n vector<int> res, postSum(nums.size(), 0);\n int post = 0, preSum = 0;\n for(int i=nums.size()-1;i>=0;i--){\n postSum[i] = post;\n post = post + nums[i];\n }\n for(int i=0;i<nums.size();i...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
3
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) \n {\n int n = nums.size();\n vector<int>prefix(n);\n prefix[0] = nums[0];\n for(int i = 1; i < nums.size(); i++)\n prefix[i] = prefix[i - 1] + nums[i];\n \n vecto...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
3
{ "code": "static auto _ = [](){ios::sync_with_stdio(false); cin.tie(nullptr); return nullptr;}();\nclass Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n vector<int> res, postSum(nums.size(), 0);\n int post = 0, preSum = 0;\n for(int i=nums.size()-1;i>=0;i--){\n p...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
3
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n = nums.size();\n \n vector<int> pref(n+1,0),suf(n+1,0);\n for(int i=0;i<n;++i){\n pref[i+1]=pref[i]+nums[i];\n suf[n-i-1] = suf[n-i]+nums[n-i-1];\n }\n ...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
3
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n vector<int> ans;\n int n = nums.size();\n\n vector<int> pre(n,0);\n vector<int> suf(n,0);\n pre[0] = nums[0];\n suf[n-1] = nums[n-1];\n\n for(int i=1;i<n;i++)\n ...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
3
{ "code": "class Solution {\n public:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n // int sum=accumulate(nums.begin(),nums.end(),0);\n vector<int>ans;\n int n=nums.size();\n\n vector...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
3
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n vector<int>psum;\n int sum=0;\n for(int i=0;i<nums.size();i++){\n sum+=nums[i];\n psum.push_back(sum);\n }\n vector<int>result;\n for (int i = 0; i < n...
1,787
<p>You are given an integer array <code>nums</code> sorted in <strong>non-decreasing</strong> order.</p> <p>Build and return <em>an integer array </em><code>result</code><em> with the same length as </em><code>nums</code><em> such that </em><code>result[i]</code><em> is equal to the <strong>summation of absolute diffe...
3
{ "code": "class Solution {\npublic:\n vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n int n = nums.size();\n vector<int> prefix = {nums[0]};\n for (int i = 1; i < n; i++) {\n prefix.push_back(prefix[i - 1] + nums[i]);\n }\n \n vector<int> ans;\n ...
1,806
<p>You are given an integer <code>n</code>, the number of teams in a tournament that has strange rules:</p> <ul> <li>If the current number of teams is <strong>even</strong>, each team gets paired with another team. A total of <code>n / 2</code> matches are played, and <code>n / 2</code> teams advance to the next roun...
0
{ "code": "class Solution {\npublic:\n int numberOfMatches(int n) {\n int matches,teamadv;\n if(n&1){\n matches = (n-1)/2;\n teamadv = (n-1)/2 + 1;\n } else {\n matches = n/2;\n teamadv = n/2;\n }\n\n if(teamadv == 1){\n return matches;\n } else {\n...
1,806
<p>You are given an integer <code>n</code>, the number of teams in a tournament that has strange rules:</p> <ul> <li>If the current number of teams is <strong>even</strong>, each team gets paired with another team. A total of <code>n / 2</code> matches are played, and <code>n / 2</code> teams advance to the next roun...
0
{ "code": "class Solution {\npublic:\n int numberOfMatches(int n) {\n int suma = 0;\n while (n != 1) {\n if (n % 2) {\n suma += (n+1)/2;\n n = (n-1)/2;\n } else {\n n = n/2;\n suma += n;\n }\n }\n ...
1,806
<p>You are given an integer <code>n</code>, the number of teams in a tournament that has strange rules:</p> <ul> <li>If the current number of teams is <strong>even</strong>, each team gets paired with another team. A total of <code>n / 2</code> matches are played, and <code>n / 2</code> teams advance to the next roun...
0
{ "code": "class Solution {\npublic:\n int numberOfMatches(int n) {\n int count=0;\n while(n>1){\n if(n%2==0){\n count+=n/2;\n n=n/2;\n }else{\n count+=((n-1)/2)+1;\n n=(n-1)/2;\n }\n }\n return count; \n }\n};", "memory": "7300" }
1,806
<p>You are given an integer <code>n</code>, the number of teams in a tournament that has strange rules:</p> <ul> <li>If the current number of teams is <strong>even</strong>, each team gets paired with another team. A total of <code>n / 2</code> matches are played, and <code>n / 2</code> teams advance to the next roun...
0
{ "code": "class Solution {\npublic:\n int numberOfMatches(int n) {\n if(n==1) return 0;\n return numberOfMatches(n/2) + n/2 + n%2;\n }\n};", "memory": "7400" }
1,806
<p>You are given an integer <code>n</code>, the number of teams in a tournament that has strange rules:</p> <ul> <li>If the current number of teams is <strong>even</strong>, each team gets paired with another team. A total of <code>n / 2</code> matches are played, and <code>n / 2</code> teams advance to the next roun...
0
{ "code": "class Solution {\npublic:\n int numberOfMatches(int n) {\n int ans = 0;\n while(n != 1){\n if(n%2==0){\n ans += n/2;\n n = n/2;\n }else{\n ans += n/2;\n n = n/2 + 1;\n }\n }\n return ...
1,806
<p>You are given an integer <code>n</code>, the number of teams in a tournament that has strange rules:</p> <ul> <li>If the current number of teams is <strong>even</strong>, each team gets paired with another team. A total of <code>n / 2</code> matches are played, and <code>n / 2</code> teams advance to the next roun...
0
{ "code": "class Solution {\npublic:\n int numberOfMatches(int n) {\n return n -1 ;\n }\n};", "memory": "7500" }
1,806
<p>You are given an integer <code>n</code>, the number of teams in a tournament that has strange rules:</p> <ul> <li>If the current number of teams is <strong>even</strong>, each team gets paired with another team. A total of <code>n / 2</code> matches are played, and <code>n / 2</code> teams advance to the next roun...
0
{ "code": "class Solution {\npublic:\n int numberOfMatches(int n) {\n \n return n-1;\n\n }\n};", "memory": "7500" }
1,807
<p>A decimal number is called <strong>deci-binary</strong> if each of its digits is either <code>0</code> or <code>1</code> without any leading zeros. For example, <code>101</code> and <code>1100</code> are <strong>deci-binary</strong>, while <code>112</code> and <code>3001</code> are not.</p> <p>Given a string <code>...
0
{ "code": "class Solution {\npublic:\n int minPartitions(string s) {\n return 0;\n }\n};\n\nauto _ = [](){\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n std::ofstream out(\"user.out\", std::ios::out | std::ios::binary);\n out.rdbuf()->pubsetbuf(nullptr, 256);\n std::noskipws(std::cin);\n...
1,807
<p>A decimal number is called <strong>deci-binary</strong> if each of its digits is either <code>0</code> or <code>1</code> without any leading zeros. For example, <code>101</code> and <code>1100</code> are <strong>deci-binary</strong>, while <code>112</code> and <code>3001</code> are not.</p> <p>Given a string <code>...
0
{ "code": "class Solution {\npublic:\n int minPartitions(string s) {\n return 0;\n }\n};\n\nauto _ = [](){\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n std::ofstream out(\"user.out\", std::ios::out | std::ios::binary);\n out.rdbuf()->pubsetbuf(nullptr, 256);\n std::noskipws(std::cin);\n...
1,807
<p>A decimal number is called <strong>deci-binary</strong> if each of its digits is either <code>0</code> or <code>1</code> without any leading zeros. For example, <code>101</code> and <code>1100</code> are <strong>deci-binary</strong>, while <code>112</code> and <code>3001</code> are not.</p> <p>Given a string <code>...
0
{ "code": "class Solution {\npublic:\n int minPartitions(string s) {\n return 0;\n }\n};\n\nauto _ = [](){\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n std::ofstream out(\"user.out\", std::ios::out | std::ios::binary);\n out.rdbuf()->pubsetbuf(nullptr, 256);\n std::noskipws(std::cin);\n...
1,807
<p>A decimal number is called <strong>deci-binary</strong> if each of its digits is either <code>0</code> or <code>1</code> without any leading zeros. For example, <code>101</code> and <code>1100</code> are <strong>deci-binary</strong>, while <code>112</code> and <code>3001</code> are not.</p> <p>Given a string <code>...
0
{ "code": "class Solution {\npublic:\n// 27346209830709182346\n// 11111101110101111111\n// 1623510872060807\n\n// time complexety O(n)\n// memory required O(1)\n int minPartitions(const std::string& n) {\n if (n.empty()) {\n return 0;\n }\n int result = 0;\n for (char digit :...
1,807
<p>A decimal number is called <strong>deci-binary</strong> if each of its digits is either <code>0</code> or <code>1</code> without any leading zeros. For example, <code>101</code> and <code>1100</code> are <strong>deci-binary</strong>, while <code>112</code> and <code>3001</code> are not.</p> <p>Given a string <code>...
0
{ "code": "class Solution {\npublic:\n int minPartitions(const std::string& n) {\n char max_digit=*std::max_element(n.begin(),n.end());\n return max_digit-'0';\n }\n};", "memory": "13300" }
1,807
<p>A decimal number is called <strong>deci-binary</strong> if each of its digits is either <code>0</code> or <code>1</code> without any leading zeros. For example, <code>101</code> and <code>1100</code> are <strong>deci-binary</strong>, while <code>112</code> and <code>3001</code> are not.</p> <p>Given a string <code>...
0
{ "code": "class Solution {\npublic:\n int minPartitions(const string& n) {\n int max{ 0 }, digit;\n for (const char& c : n)\n {\n digit = c - '0';\n if (digit > max)\n {\n max = digit;\n }\n }\n return max;\n }\n};", ...
1,807
<p>A decimal number is called <strong>deci-binary</strong> if each of its digits is either <code>0</code> or <code>1</code> without any leading zeros. For example, <code>101</code> and <code>1100</code> are <strong>deci-binary</strong>, while <code>112</code> and <code>3001</code> are not.</p> <p>Given a string <code>...
0
{ "code": "class Solution {\npublic:\n static int minPartitions(const std::string& n) {\n std::map<char, int> m;\n for (const auto c : n)\n ++m[c];\n\n return m.rbegin()->first - '0';\n }\n};", "memory": "14600" }
1,807
<p>A decimal number is called <strong>deci-binary</strong> if each of its digits is either <code>0</code> or <code>1</code> without any leading zeros. For example, <code>101</code> and <code>1100</code> are <strong>deci-binary</strong>, while <code>112</code> and <code>3001</code> are not.</p> <p>Given a string <code>...
0
{ "code": "class Solution {\npublic:\n static int minPartitions(const std::string& n) {\n std::map<char, int> m;\n for (const auto c : n)\n ++m[c];\n\n return m.rbegin()->first - '0';\n }\n};", "memory": "14600" }
1,807
<p>A decimal number is called <strong>deci-binary</strong> if each of its digits is either <code>0</code> or <code>1</code> without any leading zeros. For example, <code>101</code> and <code>1100</code> are <strong>deci-binary</strong>, while <code>112</code> and <code>3001</code> are not.</p> <p>Given a string <code>...
0
{ "code": "class Solution {\npublic:\n int minPartitions(string n) {\n int sum = 0 ; \n for(char&c : n){\n sum = max(sum , c - '0');\n }\n return sum ; \n }\n};", "memory": "14800" }
1,807
<p>A decimal number is called <strong>deci-binary</strong> if each of its digits is either <code>0</code> or <code>1</code> without any leading zeros. For example, <code>101</code> and <code>1100</code> are <strong>deci-binary</strong>, while <code>112</code> and <code>3001</code> are not.</p> <p>Given a string <code>...
0
{ "code": "\nclass Solution {\n public:\n int minPartitions(string n) {\n return ranges::max(n) - '0';\n }\n};", "memory": "14800" }
1,807
<p>A decimal number is called <strong>deci-binary</strong> if each of its digits is either <code>0</code> or <code>1</code> without any leading zeros. For example, <code>101</code> and <code>1100</code> are <strong>deci-binary</strong>, while <code>112</code> and <code>3001</code> are not.</p> <p>Given a string <code>...
0
{ "code": "class Solution {\npublic:\n int minPartitions(string n) {\n char mx = '1';\n for(auto &it: n){\n mx = max(mx,it);\n } \n return (int) mx-'0';\n }\n};", "memory": "14900" }
1,807
<p>A decimal number is called <strong>deci-binary</strong> if each of its digits is either <code>0</code> or <code>1</code> without any leading zeros. For example, <code>101</code> and <code>1100</code> are <strong>deci-binary</strong>, while <code>112</code> and <code>3001</code> are not.</p> <p>Given a string <code>...
0
{ "code": "class Solution {\npublic:\n int minPartitions(string n) {\n int max = 0;\n for(int i=0; i<n.size(); i++) if(n[i]-48 > max) max = n[i]-48;\n\n return max;\n }\n};", "memory": "14900" }
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
0
{ "code": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string> &req_skills, vector<vector<string>> &people) {\n unordered_map<string, int> map;\n auto n = req_skills.size(), m = people.size();\n for (int i = 0; i < n...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
0
{ "code": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string> &req_skills, vector<vector<string>> &people) {\n unordered_map<string, int> map;\n auto n = req_skills.size(), m = people.size();\n for (int i = 0; i < n...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
0
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {\n int n = req_skills.size();\n int all_set = (1 << n) - 1;\n unordered_map<string, int> skill_to_index;\n for (int i = 0; i < n; i++){\n ski...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
0
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {\n int n = req_skills.size();\n int all_set = (1 << n) - 1;\n unordered_map<string, int> skill_to_index;\n for (int i = 0; i < n; i++){\n ski...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
1
{ "code": "class Solution {\npublic:\n vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people) {\n int numSkills = req_skills.size();\n int numPeople = people.size();\n unordered_map<string, int> skillToIndex; // map skill to its index in the bitmask\n\n ...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
1
{ "code": "class Solution {\npublic:\n typedef long long ll;\n unordered_map<string,ll>mp;\n ll dp[65536][60];\n ll maxi=LONG_LONG_MAX;\n ll solve(ll val,ll i,vector<vector<string>>&nums){\n if(i>=nums.size()){\n if(val==0)return 0;\n return maxi;\n }\n if(dp[...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
1
{ "code": "class Solution {\npublic:\n int choices[1<<16][60];\n int dp[1<<16][60];\n\n int helper(vector<int> &p,int ind,int curr_mask,int reqd_mask){\n //base cases:\n if(curr_mask==reqd_mask)return 0;\n if(ind==p.size()) return 1e6;\n if(dp[curr_mask][ind]!=-1)return dp[curr_ma...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
1
{ "code": "class Solution {\npublic:\n int dp[61][65536][2];\n int f(int index, int mask, int take, int numPeople, int numSkills, vector<int>& people){\n if(index==numPeople){\n int numSetBits = __builtin_popcount(mask);\n if(numSetBits==numSkills) return 0;\n return INT_...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
1
{ "code": "class Solution {\npublic:\n int dp[61][65536][2];\n int f(int index, int mask, int take, int numPeople, int numSkills, vector<int>& people){\n if(index==numPeople){\n int numSetBits = __builtin_popcount(mask);\n if(numSetBits==numSkills) return 0;\n return INT_...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
1
{ "code": "class Solution {\npublic:\n int dp[62][1<<17];\n int rec(int level,int mask,vector<vector<string>>&people,vector<string>&req_skills,map<string,int>&mp){\n \n if(level == people.size()){\n int k = req_skills.size();\n if(mask == (1<<k)-1)return 0 ;\n else...
1,220
<p>In a project, you have a list of required skills <code>req_skills</code>, and a list of people. The <code>i<sup>th</sup></code> person <code>people[i]</code> contains a list of skills that the person has.</p> <p>Consider a sufficient team: a set of people such that for every required skill in <code>req_skills</code...
1
{ "code": "class Solution {\npublic:\n int dp[62][1<<17];\n\n void f(int idx,int mask,int t,int m,vector<int>&a,vector<int>&v,vector<int>&ans){\n if(idx==m){\n if(mask==t){\n \n if(ans.size()==0 or ans.size()>=v.size())ans=v;\n }\n return;\n ...