id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n \n vector<int>ans;\n unordered_map<string, vector<int>>memo;\n\n for(int ind=0;ind<expression.length();ind++)\n {\n\n vector<int>left, right;\n char cur= expression[i... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n int n = expression.size();\n\n vector<int> ans;\n\n for(int i = 0; i < n; i++){\n if(!isdigit(expression[i])){\n string leftExp = expression.substr(0, i);\n stri... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "class Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n std::vector<int> results;\n for (int i = 0; i < expression.size(); ++i) {\n if (expression[i] == '+' || expression[i] == '-' || expression[i] == '*') {\n std::string left = expression... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "#include <vector>\n#include <string>\n#include <unordered_map>\n#include <functional>\n#include <iostream>\n\nclass Solution {\npublic:\n std::vector<int> diffWaysToCompute(std::string expression) {\n std::function<std::vector<int>(std::string)> compute = [&](std::string expr) {\n if (... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "class Solution {\npublic:\n vector<int> solve(string& e,int l,int r){\n if(l>r){return {};}\n if(l==r){return {e[l]-'0'};}\n vector<int>ans;\n int f=0;\n for(int i=l;i<=r;i++){\n if(e[i]=='+'){\n f=1;\n vector<int>left=solve(e,l... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "vector<int> f(string &s,int l,int r)\n{\n bool t=false;\n vector<int> left;\n vector<int> right;\n vector<int> ans;\n if(l==r) \n { \n ans.push_back(s[l]-'0');\n return ans;\n }\n //if(dp[l][r]!=-1)return dp[l][r];\n int a,b;\n for(int k=l;k<r;k++)\n {\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "class Solution {\npublic:\n int getNumFromString(string str) {\n int num = 0, n = str.length();\n if (n == 0) return num;\n bool neg = str[0] == '-';\n for (int i = neg ? 1 : 0; i < n; i++) {\n num *= 10;\n num += (int)str[i] - 48;\n }\n re... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "class Solution {\npublic:\n vector<int> f(int i,int j,string expression){\n vector<int> vec;\n if(i>j){\n return vec;\n }\n if(i==j){\n string str;\n str+=expression[i];\n vec.push_back(stoi(str));\n return vec;\n ... |
241 | <p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</strong>.</p>
<p>The test cases are generated such that the output values fit in a 32-bi... | 3 | {
"code": "class Solution {\npublic:\n vector<int> helper(int start, int end, string exp) {\n int length = end - start +1;\n if(length <= 2) {\n return { stoi(exp.substr(start)) };\n }\n vector<int> possibleVals;\n for(int i = start; i <= end; i++) {\n if(ex... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(string &s, string &t) {\n sort(s.begin(),s.end());\n sort(t.begin(),t.end());\n if(s==t) return true;\n else return false;\n }\n};\nstatic const int speedup = []() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n co... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(string &s, string &t) {\n sort(s.begin(),s.end());\n sort(t.begin(),t.end());\n if(s==t){\n return 1;\n }\n else return 0;\n }\n};\n",
"memory": "8300"
} |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(string &s, string &t) {\n sort(s.begin(),s.end());\n sort(t.begin(),t.end());\n if(s==t) return true;\n else return false;\n }\n};\n",
"memory": "8400"
} |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(string &s, string &t) {\n sort(s.begin(),s.end());\n sort(t.begin(),t.end());\n if(s==t) return true;\n else return false;\n }\n};\n",
"memory": "8400"
} |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n\n sort(s.begin(), s.end());\n sort(t.begin(), t.end());\n return s==t;\n }\n};",
"memory": "8500"
} |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n sort(s.begin(),s.end());\n sort(t.begin(),t.end());\n if(s==t){\n return true;\n }\n return false;\n \n }\n};",
"memory": "8500"
} |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n sort(s.begin(),s.end());\n sort(t.begin(),t.end());\n if(s==t){\n return true;\n }else{\n return false;\n }\n }\n};",
"memory": "8600"
} |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n sort(s.begin(), s.end());\n sort(t.begin(), t.end());\n return s == t;\n }\n};",
"memory": "8600"
} |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n if(s.size()!=t.size()){\n return false;\n }\n int l=s.size();\n int ar1[26];\n int ar2[26];\n for(int i=0;i<l;i++){\n ar1[s[i]-97]++;\n ar2[t[i]-97]++;\n }... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n sort(s.begin(),s.end());\n sort(t.begin(),t.end());\n if(s==t)\n return true;\n else\n return false;\n }\n};",
"memory": "8700"
} |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n vector<int> freq(26);\n for(auto& x : s) freq[x - 'a']++;\n for(auto& x : t) {\n if(freq[x - 'a'] == 0) return false;\n freq[x - 'a']--;\n }\n return !(*max_element(freq.begin(), f... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n if(s.length() != t.length()) return false;\n sort(s.begin(), s.end());\n sort(t.begin(), t.end());\n for(int i = 0; i < s.length(); i++){\n if(s[i] != t[i]) return false;\n }\n return ... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 1 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n if (s.length() == t.length()) {\n std::unordered_map<char, int> map;\n for (unsigned int i = 0; i < s.length(); i++) {\n auto it = map.find(s[i]);\n if (it != map.end()) {\n ... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 1 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n sort(s.begin(), s.end());\n sort(t.begin(), t.end());\n\n return s == t;\n }\n};",
"memory": "8900"
} |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n int hash[256]={0};\n for(int i=0;i<s.size();i++){\n hash[s[i]]++;\n }\n for(int i=0;i<t.size();i++){\n hash[t[i]]--;\n }\n for(int i=0;i<256;i++){\n if(hash[i]!=0) return false;\n ... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n int freqtable[256] = {0};\n for(int i =0; i<s.length(); i++){\n freqtable[s[i]]++;\n } \n for(int i =0; i<t.length(); i++){\n freqtable[t[i]]--;\n }\n for(int i =0; i<256; i++){\n ... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n if (s.size() != t.size()) {\n return false;\n }\n\n // Sort both strings\n string sorted_s = s;\n string sorted_t = t;\n sort(sorted_s.begin(), sorted_s.end());\n sort(sorted_t.begin(), sorted_t.end());\n\... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(std::string s, std::string t) {\n std::vector<char> s1(s.begin(), s.end());\n std::vector<char> t1(t.begin(), t.end());\n\n int slength = s1.size();\n int tlength = t1.size();\n\n if (slength!=tlength) return false;\n\n ... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n \n string ss = s;\n string tt = t;\n sort(ss.begin(),ss.end());\n sort(tt.begin(),tt.end());\n\n if(ss==tt){\n return true;\n }\n return false;\n \n }\n};",
"... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n vector<int> convTonum(string b){\n vector<int> v(26,0);\n for (char j: b){\n v[j-'a']++;\n }\n return v;\n }\n bool isAnagram(string s, string t) {\n if(s.length() != t.length()){\n return false;\n }\n ... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n if (s.size()!=t.size()){\n return false;\n }\n if (s==t){\n return true;\n }\n vector<char> svec;\n vector<char> tvec;\n\n for (int i=0; i<s.size(); i++){\n ... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n if(s.size() != t.size()) return false;\n int n = s.length(); \n vector<char>ss, tt;\n for(int i = 0;i<n;i++)\n {\n ss.push_back(s[i]);\n tt.push_back(t[i]); \n }\n so... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n if(s.length()!=t.length())\n return false;\n vector <char> s2;\n vector <char> t2;\n for(int i=0;i<s.length();i++)\n {\n s2.push_back(s[i]);\n t2.push_back(t[i]);\n ... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n #include <iostream>\n#include <string>\n#include <unordered_map>\n\n// Function to determine if two strings are anagrams of each other\nbool isAnagram(const std::string& firstWord, const std::string& secondWord) {\n\n if (firstWord.length() != secondWord.length()) {\n ... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n vector<char>a;\n vector<char>b;\n \n if(s.length()!=t.length())\n {\n return false;\n }\n for(int i=0;i<s.length();i++)\n {\n a.push_back(s[i]);\n b.push_back(t[i]);\n }\n\... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n map<char,int> mp;\n \n for(char &c : s){\n mp[c-'a']++;\n }\n for(char &c : t){\n mp[c-'a']--;\n // If any character count goes negative, the strings are not anagrams\n... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n unordered_map<char, int> mpp;\n if (s.size() != t.size()) return false;\n\n for (int i=0; i<s.size(); i++)\n {\n mpp[s[i]]++;\n }\n for (int i=0; i<t.size(); i++)\n {\n ... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n map<char,int>mp;\n int n = s.size();\n int m = t.size();\n for(int i=0;i<n;i++){\n mp[s[i]]++;\n }\n if(n==m){\n for(int j=0;j<m;j++){\n mp[t[j]]--;\n ... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(const string& s, const string& t) {\n if (s.length() != t.length()) {\n return false;\n }\n unordered_map<char, int> mp;\n for (char c : s) {\n mp[c]++;\n }\n for (char c : t) {\n mp[c]--;\n }\n for (auto& i : mp) {\n... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n std::map<char, int> m;\n for(int i=0;i<s.size(); i++) {\n if (m.count(s[i]) > 0) {\n m[s[i]]++;\n } else {\n m[s[i]] = 1;\n }\n }\n for(int i=0;i<... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n if(s.size()!=t.size())return false;\n unordered_map<char,int>map;\n for(int i = 0;i<s.size();i++)map[s[i]]++;\n for(int i = 0;i<t.size();i++)map[t[i]]--;\n for(auto& pair:map)if(pair.second !=0)return f... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n int n = s.length();\n int l = t.length();\n if(n != l) return false;\n\n unordered_map<char, int> m, m1;\n for(int i = 0; i < n; i++){\n m[s[i]]++;\n }\n\n for(int i = 0; i< l; i+... |
242 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an <span data-keyword="anagram">anagram</span> of <code>s</code>, and <code>false</code> otherwise.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</... | 2 | {
"code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n unordered_map<char,int>count;\n for( auto x :s){\n count[x]++;\n }\n for(auto x : t){\n count[x]--;\n }\n\n for(auto x : count){\n if(x.second != 0){\n ... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 0 | {
"code": "#pragma GCC optimize(\"O3\", \"unroll-loops\")\nauto init = []()\n{ \n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\nclass Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n long long sum = nums... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 0 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums){\n sort(nums.begin(), nums.end());\n long long perimeter=nums[0]+nums[1], ans=-1;\n for(int i=2;i<nums.size();i++){\n if(perimeter>nums[i]) ans=perimeter+nums[i];\n perimeter+=nums[i];\n ... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 0 | {
"code": "class Solution {\n\npublic:\n\n long long largestPerimeter(vector<int>& nums) {\n\n sort(nums.begin(), nums.end());\n\n long long previousElementsSum = 0;\n\n long long ans = -1;\n\n for (int num : nums) {\n\n if (num < previousElementsSum) {\n\n ans... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 0 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n long long prev_sum = 0;\n long long max_peri = -1; \n for(int i = 0; i< nums.size(); i++)\n {\n if(prev_sum > nums[i])\n {\n ... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 0 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n // step 1 : find the sum of all the element present in the array\n long long sum = 0 ;\n for (auto it:nums){\n sum+=it ;\n }\n // step ##: sort the nums in accending order\n ... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 1 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums)\n {\n sort(nums.begin(),nums.end());\n\n long long sum = 0;\n\n for (int i = 0; i < nums.size(); i++)\n sum += nums[i];\n\n for (int i = nums.size()-1; i >= 0; i--)\n {\n if(sum... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n long long sum = nums[0] + nums[1];\n long long res = -1;\n for (int i = 2; i <nums.size(); i++){\n if (sum > nums[i]){\n res = max(res, su... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n sort(nums.rbegin(), nums.rend());\n long long sum = 0;\n for (int i = 0; i < nums.size(); i++) {\n sum += nums[i];\n }\n for (int i = 0; i < nums.size(); i++) {\n if (nu... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n long long prefix[n+1];\n prefix[0]=1LL*nums[0];\n for(int i=1;i<n;i++){\n prefix[i]=prefix[i-1]+1LL*nums[i];\n }\n ... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n= nums.size();\n int i=n-1;\n long long s=0;\n long long arr[n];\n for(int j=0;j<n;j++){\n s+=nums[j];\n arr[j]=s;\n ... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\n public:\n auto largestPerimeter(std::vector<int> nums) -> long long {\n int n = static_cast<int>(nums.size());\n long long perimeter = std::accumulate(nums.begin(), nums.end(), 0LL);\n for (int i = 0; i < n - 2; i++) {\n std::nth_element(nums.begin() + i, nums.begin() + i,... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "#pragma GCC optimize(\"O3\", \"unroll-loops\")\nclass Solution {\n public:\n auto largestPerimeter(std::vector<int> nums) -> long long {\n int n = static_cast<int>(nums.size());\n long long perimeter = std::accumulate(nums.begin(), nums.end(), 0LL);\n for (int i = 0; i < n - 2; i++) {\n std:... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\n public:\n auto largestPerimeter(std::vector<int> nums) -> long long {\n int n = static_cast<int>(nums.size());\n long long perimeter = std::accumulate(nums.begin(), nums.end(), 0LL);\n for (int i = 0; i < n - 2; i++) {\n std::nth_element(nums.begin() + i, nums.begin() + i,... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\n public:\n auto largestPerimeter(std::vector<int> nums) -> long long {\n int n = static_cast<int>(nums.size());\n long long perimeter = std::accumulate(nums.begin(), nums.end(), 0LL);\n for (int i = 0; i < n - 2; i++) {\n std::nth_element(nums.begin() + i, nums.begin() + i,... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\n public:\n auto largestPerimeter(std::vector<int> nums) -> long long {\n sort(nums.begin(), nums.end());\n long long res = -1;\n long long curr = 0;\n for (int num : nums) {\n if ((curr += num) > num * 2) {\n res = curr;\n }\n }\n return res;\n }\n};\n... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n priority_queue<int, vector<int>, greater<int>> pq(nums.begin(), nums.end());\n long long sum = pq.top();\n pq.pop();\n sum += pq.top();\n pq.pop();\n long long ans = -1;\n while... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n long long sum = accumulate(nums.begin(), nums.end(), 0LL);\n priority_queue<int> pq(nums.begin(), nums.end());\n while (pq.size() > 2) {\n int num = pq.top();\n if (sum > 2*num) retur... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\npublic:\nlong long findsum(vector<int>nums,int idx){\n long long ans=0;\n for(int i=0;i<=idx;i++){\n ans+=nums[i];\n }\n return ans;\n}\n long long largestPerimeter(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n long long ans=-1;\n for(i... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& a) \n {\n sort(a.begin(),a.end());\n int n=a.size();\n vector<long long>pre(n);\n pre[0]=a[0];\n for(int i=1;i<n;i++)\n {\n pre[i]=pre[i-1]+a[i];\n }\n long long ans=... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n vector<long long> prefix(n);\n for(int i=0;i<n;++i){\n if(i)prefix[i]=prefix[i-1]+nums[i];\n else prefix[i]=nums[i];\n ... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 2 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n std::sort(nums.begin(), nums.end());\n vector<long long> sum(nums.size() + 1);\n for (int i = 0; i < nums.size(); ++i) {\n sum[i + 1] = sum[i] + nums[i];\n }\n for (int i = nums.si... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 3 | {
"code": "#define ll long long\nclass Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(),nums.end());\n vector<ll> prefix(n);\n prefix[0] = nums[0];\n for(int i=1;i<n;i++)\n {\n prefix[i] = prefix[i-... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 3 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n vector<long long> prefix(n,0LL);\n\n for(int i=0; i<n; i++){\n if(i==0) prefix[i] = nums[i];\n else prefix[i] = prefix[... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 3 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n vector<long long>preSum(nums.size(),0);\n preSum[0] = nums[0];\n for(int i=1;i<nums.size();i++){\n preSum[i] = preSum[i-1]+nums[i];\n }\n\n ... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 3 | {
"code": "#define lli long long\nclass Solution {\npublic:\n vector<int> arr;\n vector<lli> prefix;\n long long largestPerimeter(vector<int>& nums) {\n arr=nums;\n sort(arr.begin(),arr.end());\n int n=arr.size();\n prefix.resize(n+1);prefix[0]=0;\n for(int i=0;i<n;i++){\n ... |
3,262 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
... | 3 | {
"code": "class Solution {\npublic:\n long long largestPerimeter(vector<int>& nums) {\n priority_queue<long long> pq;\n long long sum=0;\n for(int i=0;i<nums.size();i++){\n sum+=nums[i];\n pq.push(nums[i]);\n }\n while(!pq.empty()){\n long long t... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\n public:\n int solve(vector<int>&nums,int index,int k,unordered_map<int,int>&mp){\n if(index>=nums.size())return 1;\n int notTake=solve(nums,index+1,k,mp);\n int take=0;\n if(!mp[nums[index] - k] && !mp[nums[index] + k]){\n mp[nums[index]]++;\n take=solve(nums,i... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int help(map<int,int>& arr,int k){\n int next1=1;int next2=1;\n for(auto it=arr.rbegin();it!=arr.rend();it++){\n int pick=0;\n \n if(it!=arr.rbegin()){\n if(arr.find(it->first+k)!=arr.end()){\n pick=(pow(2,it->second)-1)*next... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> valid(1 << n, 0);\n valid[0] = 1;\n int res = 0;\n for (int state = 1; state < (1 << n); state += 1) {\n int i = n - 1;\n while (i >=... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int dp[21][1<<20];\n int help(int i,int n,vector<int>&nums,int k,int mask){\n if(i==n) return 1;\n if(dp[i][mask]!=-1) return dp[i][mask];\n int t=0,nt=0;\n nt=help(i+1,n,nums,k,mask);\n bool c=1;\n for(int j=0; j<n; j++){\n ... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n int n =int(nums.size());\n\n int r=n;\n vector<int> nums2;\n\n for(int i=0;i<n;++i)\n {\n nums2.clear();\n \n for(int j=i+1;j<n;++j)\n if(abs(nums[i]-nums[j])!=k)\n ... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n\n //sort(nums.begin(),nums.end());\n\n int n =int(nums.size());\n\n int r=n;\n\n\n vector<int> nums2;\n for(int i=0;i<n;++i)\n {\n nums2.clear();\n \n for(int j=i+1;j<n;+... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n\n //sort(nums.begin(),nums.end());\n\n int n =int(nums.size());\n\n int r=n;\n\n\n vector<int> nums2;\n for(int i=0;i<n;++i)\n {\n nums2.clear();\n \n for(int j=i+1;j<n;+... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n int n =int(nums.size());\n\n int r=n;\n vector<int> nums2;\n nums2.reserve(n);\n \n for(int i=0;i<n;++i)\n {\n nums2.clear();\n \n for(int j=i+1;j<n;++j)\n ... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n int n =int(nums.size());\n\n int r=n;\n vector<int> nums2;\n nums2.reserve(n);\n \n for(int i=0;i<n;++i)\n {\n nums2.clear();\n \n for(int j=i+1;j<n;++j)\n ... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\n unordered_map<int, int> mp;\n int ans = 0;\n\npublic:\n void solve(vector<int>& nums, int k, int start) {\n // Increment ans for each valid subset\n if (!mp.empty()) ans++;\n\n // Iterate through the remaining elements\n for (int i = start; i < nums.s... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n \n dfs(nums, k, 0);\n return _ct;\n }\n\nprivate:\n int _ct = 0;\n unordered_map<int, int> _map;\n\n void dfs(const vector<int>& nums, int k, int start) {\n if (_map.size() != 0) _ct++;... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\n unordered_map<int, int> mp;\n int ans = 0;\n\npublic:\n void solve(vector<int>& nums, int k, int start) {\n // Increment ans for each valid subset\n if (!mp.empty()) ans++;\n\n // Iterate through the remaining elements\n for (int i = start; i < nums.s... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n void helper(vector<int> &nums,int k,int &ans,int idx,unordered_map<int,int> &m1){\n if(idx==nums.size()){\n return;\n }\n for(int i=idx;i<nums.size();i++){\n if((m1.find(nums[i]+k)==m1.end() && m1.find(nums[i]-k)==m1.end())){\n ... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "// Tag: Backtracking\n\n// Create Date: 2024/5/23\n// Review Date: [2024/5/30, 2024/6/25]\n\n#include <bits/stdc++.h> \nusing namespace std;\n\n// O(2^n)Time, O(n)Space, 因为potentially需要generate all subsets\nclass Solution {\npublic:\n void backtracking(const vector<int>& nums, const int k,\n ... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n void helper(vector<int> &nums,int k,int &ans,int idx,unordered_map<int,int> &m1){\n if(idx==nums.size()){\n return;\n }\n for(int i=idx;i<nums.size();i++){\n if((m1.find(nums[i]+k)==m1.end() && m1.find(nums[i]-k)==m1.end())){\n ... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n\n sort(nums.begin(),nums.end());\n\n int n =int(nums.size());\n\n int r=n;\n for(int i=0;i<n;++i)\n {\n vector<int> nums2;\n \n for(int j=i+1;j<n;++j)\n if(abs(nums[i]-... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n\n /**s contiene gli indici degli elementi appartenenti alla subset\n subset distinte !!!**/\n void dfs(vector<int> &s,int x,vector<int> &A,int k,int &number,unordered_map<int,int> &cnt){\n \n vector<int> candidates;\n\n /**se la differenza tra cnt[A... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n\n /**s contiene gli indici degli elementi appartenenti alla subset\n subset distinte !!!**/\n void dfs(vector<int> &s,int x,vector<int> &A,int k,int &number,vector<int> &cnt){\n \n vector<int> candidates;\n\n /**se la differenza tra cnt[A[i] -k] è m... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n unordered_multiset<int> st;\n int res = 0;\n for (int i = 0; i < nums.size(); ++i)\n dfs(nums, i, st, k, res);\n return res;\n }\n\nprivate:\n void dfs(const vector<int>& nums, int... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n\n /**s contiene gli indici degli elementi appartenenti alla subset\n subset distinte !!!**/\n void dfs(vector<int> &s,int x,vector<int> &A,int k,int &number,vector<int> &cnt){\n \n vector<int> candidates;\n\n /**se la differenza tra cnt[A[i] -k] è m... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n\n /**s contiene gli indici degli elementi appartenenti alla subset\n subset distinte !!!**/\n void dfs(vector<int> &s,int x,vector<int> &A,int k,int &number,vector<int> &cnt){\n \n vector<int> candidates;\n\n /**se la differenza tra cnt[A[i] -k] è m... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n int count = -1;\n vector<int> curr;\n unordered_multiset<int> s;\n makeSubsets(0, curr, nums, k, count, s);\n\n return count;\n\n }\n\n void makeSubsets(int index, vector<int> &curr, v... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int f(int i,int mask,vector<int>&nums,vector<vector<int>>&dp,int &k){\n if(i<0){\n \n if(mask!=0)return 1;\n return 0;\n }\n if(dp[i][mask]!=-1)return dp[i][mask];\n int nottake=f(i-1,mask,nums,dp,k);\n int t... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int f(int i,int mask,vector<int>&nums,vector<vector<int>>&dp,int &k){\n if(i<0){\n \n if(mask!=0)return 1;\n return 0;\n }\n if(dp[i][mask]!=-1)return dp[i][mask];\n int nottake=f(i-1,mask,nums,dp,k);\n int t... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n map<vector<int>,int> cache;\n\n vector<bool> marked(nums.size(),false);\n\n return imp(nums,nums.size(),k,0,cache,marked);\n }\n\n int imp(vector<int>& nums, int n, int k,int start,map<vector<int>,int>... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int dfs(vector<int> &nums, int idx, int mask, int k, vector<vector<int>> &dp) {\n int n = nums.size();\n if (idx == n) return 1; // Base case: consider all elements\n\n if (dp[idx][mask] != -1) return dp[idx][mask]; // Return memoized result\n\n //... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<int>> dp(n + 1, vector<int>(1 << n, -1)); // dp table to store results\n sort(nums.begin(), nums.end()); // Sort nums to ensure we handle subsets properly\n\n r... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\nprivate:\n\n void subsets(vector<vector<int> >& res, vector<int>& curr, vector<int>& nums, int k, int idx){\n\n\n for(int i=idx ;i<nums.size() ;i++){\n\n bool isvalid = true;\n\n for(int num : curr){\n if(abs(num - nums[i]) == k){\n... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n bool valid(vector<int> &arr, int k)\n {\n for (int i = 0; i < arr.size(); i++)\n {\n for (int j = i + 1; j < arr.size(); j++)\n {\n if (abs(arr[i] - arr[j]) == k) return false;\n }\n }\n return tru... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n vector<vector<int>> res;\n vector<int> arr;\n dfs(nums, k, 0, res, arr);\n return res.size();\n }\n void dfs(vector<int>& nums, int k, int i, vector<vector<int>>& res, vector<int>& arr) {\n ... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> result;\n void backtrack(vector<int>& nums, int index, int k, unordered_map<int, int>& count, vector<int>& subsets) {\n for(int i = index; i < nums.size(); i ++) {\n if(count[nums[i] - k] || count[nums[i]+k]) continue;\n sub... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n int cnt = 0;\n\n for (int bitmask = 1; bitmask < (1 << nums.size()); ++bitmask) {\n bool valid = true;\n vector<bool> is_here(1000, false);\n\n for (int i = 0; i < nums.size(); +... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.