id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
0
{ "code": "class Solution {\npublic:\n Solution() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n }\n\n long long beautifulSubstrings(string s, int k) {\n auto n = s.size();\n unordered_set<char> vowels{'a', 'e', 'i', 'o', 'u'};\n\n i...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
0
{ "code": "class Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n \n vector<long long>diff(s.size(),0);\n long long vow=0;\n long long con=0;\n long long ans=0;\n if(k==1)\n {\n for(int i=0;i<s.size();i++)\n {\n i...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
0
{ "code": "class Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n int len{1};\n for (; len * len % (k * 4); ++len) ;\n vector<unordered_map<int, int>> dp(len);\n dp[len - 1][0] = 1;\n long long res{0};\n for (int i = 0, v = 0; i < s.size(); ++i) {\...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
0
{ "code": "class Solution {\npublic:\n#define ll long long \n long long beautifulSubstrings(string s, int k) {\n ll newk=1,tempk=k;\n ll z=2,n=s.size();\n while(z*z<=tempk){\n ll cnt=0;\n while(tempk%z==0)tempk/=z,cnt++;\n newk*=(pow(z,(cnt+1)/2));\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n //vows == consonants\n //string length l, so l/2*(l/2)%k==0\n int n = s.length();\n int l;\n //vows - consonants\n int v = 0;\n //find smallest l\n for (l = 1; l ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n int n = s.length(), v = 0, l;\n for (l = 1; l * l % (k * 4); ++l);\n set<char> vowels = {'a', 'e', 'i', 'o', 'u'};\n vector<unordered_map<int, int>> seen(l);\n seen[l - 1][0] = 1;\n l...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n//we can count the difference between vowels and consonants in prefix substring,\n//and count the count in a hashmap,\n//count occurrences using hashmap and difference prefixsum\n long long beautifulSubstrings(string s, int k) {\n int n = s.length();\n\n //holds ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n int n = s.length(), v = 0, l;\n for (l = 1; l * l % (k * 4); ++l);\n set<char> vowels = {'a', 'e', 'i', 'o', 'u'};\n vector<unordered_map<int, int>> seen(l);\n seen[l - 1][0] = 1;\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n unordered_map<int, vector<int>> grps;\n grps[0].push_back(0);\n\n string vowels(\"aeiou\");\n for (int i = 0, presum = 0; i < s.size(); i++) {\n vowels.find(s[i]) != string::npos ? ++presum : --presum;\n g...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n unordered_map<int, vector<int>> grps;\n grps[0].push_back(0);\n\n string vowels(\"aeiou\");\n for (int i = 0, presum = 0; i < s.size(); i++) {\n vowels.find(s[i]) != string::npos ? ++pre...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n unordered_map<int, vector<int>> grps;\n grps[0].push_back(0);\n\n string vowels(\"aeiou\");\n for (int i = 0, presum = 0; i < s.size(); i++) {\n vowels.find(s[i]) != string::npos ? ++presum : --presum;\n g...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n long long ans=0;\n unordered_map<int,vector<int> >m;\n int sum=0;\n m[0].push_back(-1);\n\n for(int i=0;i<s.size();i++){\n if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n#define ll long long \n long long beautifulSubstrings(string s, int k) {\n ll newk=1,tempk=k;\n ll z=2,n=s.size();\n while(z*z<=tempk){\n ll cnt=0;\n while(tempk%z==0)tempk/=z,cnt++;\n newk*=(pow(z,(cnt+1)/2));\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n using ll = long long;\n\n bool isvowel(char c) {\n return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');\n }\n\n long long beautifulSubstrings(string s, int k) {\n vector<ll> delta(s.size() + 1, 0);\n for(ll i = 1; i <= s.size(); i++...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "#include <vector>\n#include <unordered_map>\n#include <string>\n\nclass Solution {\npublic:\n int beautifulSubstrings(const std::string& s, int k) {\n int n = s.length();\n int g = 0;\n\n // Finding the first g value\n for (int i = 1; i <= n / 2; ++i) {\n if ((i * ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "#define ll long long int\n#define pb push_back\nclass Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n /*Brute Force:- Similar approch to number of subarray with sum k type brute force*/\n ll vwl=0;\n ll cnst=0;\n unordered_map<ll,vector<ll>> dp;\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n int kk=1;\n for(int i=2;i<=k;i++){\n int cnt=0;\n while(k%i==0){\n k/=i;\n cnt++;\n }\n for(int j=0;j<(cnt+1)/2;j++)\n kk*...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "#define ll long long\n#define pii pair<ll,ll>\nclass Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n//if x*x is divisible by k we will find the minimum requirement k1 such if x is divisible by k1 then x*x is divisible by k.\n//if k=(p1^a1)*(p2^a2)...,then k1=(p1^ceil(a1/2))*(p1^...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "#define ll long long\n#define pii pair<ll,ll>\nclass Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n//if x*x is divisible by k we will find the minimum requirement k1 such if x is divisible by k1 then x*x is divisible by k.\n//if k=(p1^a1)*(p2^a2)...,then k1=(p1^ceil(a1/2))*(p1^...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "typedef long long int llt;\nclass Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n llt answer = 0;\n unordered_map<llt,vector<llt>> mp;\n mp[0].push_back(-1);\n llt v = 0 , c = 0;\n unordered_set<char> st;\n st.insert('a') , st.insert('e'...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "#define ll long long\nclass Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n unordered_map<int,vector<int>>mp;\n mp[0].push_back(0);\n int dif=0;\n ll ans=0;\n for(int i=0; i<s.length(); i++){\n if(s[i]=='a' || s[i]=='e' || s[i]=='i' ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "#define ll long long int\n\nclass Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n unordered_set<int>v;\n int n=s.length();\n for(int i=2;i<=n;i+=2){\n int j=i/2;\n if((j*j)%k==0) v.insert(i);\n }\n unordered_map<int,vector...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "#define ll long long int\n\nclass Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n unordered_set<int>v;\n int n=s.length();\n // v.insert(1);\n for(int i=2;i<=n;i+=2){\n int j=i/2;\n if((j*j)%k==0) v.insert(i);\n }\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\n const string VOWELS = \"aeiou\";\n int isVowel(char ch) {\n if (VOWELS.find(ch) != std::string::npos) {\n return 1;\n }\n return -1;\n }\n int fastExpo(int x, int n) {\n if (n == 0) {\n return 1;\n }\n int a = fa...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n int beautifulSubstrings(const string &s, int k) \n {\n // SOL-1: Brute Force -- TC: O(N^2), SC: O(1) -- TLE -- 653/684 TCs passed -- 95.47%\n // return sol1BruteForce(s, k);\n \n // SOL-2: Prefix Sum -- TC: O(N), SC: O(N)\n return sol2Pre...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n int n = s.size();\n int vowels = 0;\n int cons = 0;\n long long ans = 0;\n unordered_map<int,unordered_map<int,int>>mp;\n\n mp[0][0]++;\n\n for(int i=0;i<n;i++){\n\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n #define ll long long\n bool isVowel(char ch){\n return (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u');\n }\n long long beautifulSubstrings(string s, int k) {\n ll v = 0;\n ll c = 0;\n\n unordered_map<int, unordered_map<int,int>> mpp;\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "\nclass Solution {\npublic:\n bool isVowel(char ch){ \n return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';\n }\n\n int beautifulSubstrings(string s, int k) {\n int vowel = 0;\n int consonant = 0;\n int result = 0;\n\n unordered_map<int, unorder...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "\nclass Solution {\npublic:\n bool isVowel(char ch){ \n return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';\n }\n\n int beautifulSubstrings(string s, int k) {\n int vowel = 0;\n int consonant = 0;\n int result = 0;\n\n unordered_map<int, unorder...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n void optimizeIO() {\n std::ios_base::sync_with_stdio(false); \n std::cout.tie(nullptr); \n std::cin.tie(nullptr); \n}\n long long beautifulSubstrings(string s, int k) {\n optimizeIO();\n int n = s.size();\n int vowels = 0;\n int cons = ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n void optimizeIO() {\n std::ios_base::sync_with_stdio(false); \n std::cout.tie(nullptr); \n std::cin.tie(nullptr); \n}\n long long beautifulSubstrings(string s, int k) {\n optimizeIO();\n int n = s.size();\n int vowels = 0;\n int cons = ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
1
{ "code": "class Solution {\npublic:\n\n#define ll long long\nunordered_set<char>st={'a','e','i','o','u'};\n\n long long beautifulSubstrings(string s, int k) {\n int n=s.size();\n int ans=0;\n\n int v=0,c=0;\n\n unordered_map<int,unordered_map<int,int>>mp;\n mp[0][0]=1;\n\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "class Solution {\npublic:\n \n long long beautifulSubstrings(string s, int k)\n {\n unordered_map<long long,map<long long,long long>>mp;\n long long vowels =0,consonants =0;\n long long ans =0;\n mp[0][0] = 1;\n for(int i =0;i<s.size();i++)\n {\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "class Solution {\npublic:\n \n long long beautifulSubstrings(string s, int k)\n {\n unordered_map<long long,map<long long,long long>>mp;\n long long vowels =0,consonants =0;\n long long ans =0;\n mp[0][0] = 1;\n for(int i =0;i<s.size();i++)\n {\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "class Solution {\npublic:\n const vector<int> vprime={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};\n int Calc(int b)\n {\n int a=1;\n for(int p:vprime)\n {\n if(b==1) break;\n if(b%p!=0) continue;\n int c=0;\n for(;b%p==0;b/=p)\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "class Solution {\npublic:\n #define ll long long\n long long beautifulSubstrings(string s, int k) {\n int n=s.size();\n ll v=0;\n ll c=0;\n ll ans=0;\n map<ll,map<ll,ll>>mp;\n mp[0][0]=1;\n\n for(auto &ch:s)\n {\n if(ch=='a' or ch=='e...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "typedef long long int ll;\nclass Solution {\npublic:\n bool vow(char c){\n return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');\n }\n long long beautifulSubstrings(string s, int k) {\n ll n = s.length();\n ll c = 0, v = 0, ans = 0;\n map<ll, map<ll, ll>> m...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "class Solution {\npublic:\n #define ll long long\n bool isVowel(char ch){\n return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';\n }\n int beautifulSubstrings(string s, int k) {\n // generate all substrings:-\n ll vowel = 0;\n ll consonants = 0;\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "class Solution {\npublic:\n #define ll long long\n long long beautifulSubstrings(string s, int k) {\n int n=s.size();\n ll v=0;\n ll c=0;\n ll ans=0;\n map<ll,map<ll,ll>>mp;\n mp[0][0]=1;\n\n for(auto &ch:s)\n {\n if(ch=='a' or ch=='e...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "class Solution {\npublic:\n void optimizeIO() {\n std::ios_base::sync_with_stdio(false); \n std::cout.tie(nullptr); \n std::cin.tie(nullptr); \n}\n long long beautifulSubstrings(string s, int k) {\n optimizeIO();\n int n = s.size();\n int vowels = 0;\n int cons = ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "typedef long long int ll;\nclass Solution {\npublic:\n bool vow(char c){\n return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');\n }\n long long beautifulSubstrings(string s, int k) {\n ll n = s.length();\n ll c = 0, v = 0, ans = 0;\n map<ll, map<ll, ll>> m...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "// Idea: balance for +/-1, sliding window, prefix sum, hashtable index and\n// lookup.\n//\n// For a good length (of vowel/consonant) m that m*m is divisible by k,\n// it's O(n) to find the good substrings of length 2m that are valid.\n// But for m = 1, 2, ..., n/2, we have to run the first algorithm O(m) ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "// Idea: balance for +/-1, prefix sum, hashtable index and lookup.\n//\n// For a good length (of vowel/consonant) m that m*m is divisible by k,\n// it's O(n) to find the good substrings of length 2m that are valid.\n// But for m = 1, 2, ..., n/2, we have to run the first algorithm O(m) = O(n/2) times.\n// ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "// Idea: balance for +/-1, sliding window, prefix sum, hashtable index and\n// lookup.\n//\n// For a good length (of vowel/consonant) m that m*m is divisible by k,\n// it's O(n) to find the good substrings of length 2m that are valid.\n// But for m = 1, 2, ..., n/2, we have to run the first algorithm O(m) ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "class Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n // Hack of building a new K'\n map<int,int> fact_k;\n int temp = k;\n int k_ = 1;\n for(int i = 2;i*i < s.size();i++){\n int cnt = 0;\n while((temp%i) == 0){\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "// //Approach-1 : (Using Simple Finding substrings)\n// //T.C : O(n^2)\n// //S.C : O(1)\n// class Solution {\n// public:\n// bool isVowel(char c) {\n// return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');\n// }\n// int beautifulSubstrings(string s, int k) {\n// int...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "class Solution {\npublic:\n #define ll long long\n\n bool isVowel(char ch) \n {return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';}\n\n long long beautifulSubstrings(string s, int k) \n {\n ll vowel = 0;\n ll consonant = 0;\n\n ll result = 0;\n\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
2
{ "code": "class Solution {\n#define ll long long\n\npublic:\n bool isvowel(char ch) {return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';}\n \n ll beautifulSubstrings(string s, int k) {\n ll a = 0, b = 0, ans = 0;\n unordered_map<ll, unordered_map<ll, ll>> mp;\n mp[0][0...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
3
{ "code": "class Solution {\npublic:\n #define ll long long\n\n bool isVowel(char ch) {\n return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';\n }\n\n long long beautifulSubstrings(string s, int k) {\n ll vowel = 0;\n ll consonant = 0;\n\n ll result = 0;\n\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
3
{ "code": "class Solution {\npublic:\n #define ll long long\n \n bool isvowel(char ch) {return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';}\n \n ll beautifulSubstrings(string s, int k) {\n ll a = 0, b = 0, ans = 0;\n unordered_map<ll, unordered_map<ll, ll>> mp;\n ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
3
{ "code": "class Solution {\ntypedef long long ll; \npublic:\n long long beautifulSubstrings(string s, int k) {\n int n=s.length();\n unordered_set<char>vowels;\n vowels.insert('a');\n vowels.insert('e');\n vowels.insert('i');\n vowels.insert('o');\n vowels.inser...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
3
{ "code": "class Solution \n{\npublic:\n long long beautifulSubstrings(string s, int k) \n {\n unordered_map<int, vector<int>> m;\n long long ans = 0;\n int c = 0, n = s.size();\n\n for(int i = 0; i <= n; i++)\n {\n m[c].push_back(i);\n if(i < n) c ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
3
{ "code": "class Solution \n{\npublic:\n long long beautifulSubstrings(string s, int k) \n {\n unordered_map<int, vector<int>> m;\n long long ans = 0;\n int c = 0, n = s.size();\n\n for(int i = 0; i <= n; i++)\n {\n m[c].push_back(i);\n if(i < n) c ...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n ll n = s.size();\n unordered_map<ll, unordered_map<ll, ll>> mp;\n ll v = 0, c = 0;\n vector<ll> pref(n, 0);\n\n for (ll i = 0; i < n; i++) {\n if (s[i] == 'a...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
3
{ "code": "#define ll long long\n#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)\ntemplate <typename Arg1>\nvoid __f(const char *name, Arg1 &&arg1) {\n cout << name << \" : \" << arg1 << endl;\n}\ntemplate <typename Arg1, typename... Args>\nvoid __f(const char *names, Arg1 &&arg1, Args &&...args) {\n const char *co...
3,208
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p> <p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p> <p>A string is <strong>beautiful</strong> if:</p> <ul> <li><code>vowels == consonants</code>.</li> <li><code>(vowels * c...
3
{ "code": "#define ll long long\n#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)\ntemplate <typename Arg1>\nvoid __f(const char *name, Arg1 &&arg1) {\n cout << name << \" : \" << arg1 << endl;\n}\ntemplate <typename Arg1, typename... Args>\nvoid __f(const char *names, Arg1 &&arg1, Args &&...args) {\n const char *co...
3,221
<p>You are given a <strong>0-indexed</strong> array <code>mountain</code>. Your task is to find all the <strong>peaks</strong> in the <code>mountain</code> array.</p> <p>Return <em>an array that consists of </em>indices<!-- notionvc: c9879de8-88bd-43b0-8224-40c4bee71cd6 --><em> of <strong>peaks</strong> in the given a...
0
{ "code": "class Solution {\npublic:\n vector<int> findPeaks(vector<int>& nums) {\n int n = nums.size();\n vector<int> ans;\n\n // if(nums[0] > nums[1]) ans.push_back(0);\n // if(nums[n-1] > nums[n-2]) ans.push_back(n-1);\n\n for(int i=1; i<n-1; i++)\n {\n if(nu...
3,221
<p>You are given a <strong>0-indexed</strong> array <code>mountain</code>. Your task is to find all the <strong>peaks</strong> in the <code>mountain</code> array.</p> <p>Return <em>an array that consists of </em>indices<!-- notionvc: c9879de8-88bd-43b0-8224-40c4bee71cd6 --><em> of <strong>peaks</strong> in the given a...
0
{ "code": "class Solution\n{\npublic:\n vector<int> findPeaks(vector<int> &mountain)\n {\n vector<int> output;\n for (int i = 1; i < mountain.size() - 1; i++)\n {\n if (mountain[i] > mountain[i - 1] && mountain[i] > mountain[i + 1])\n {\n output.push_bac...
3,221
<p>You are given a <strong>0-indexed</strong> array <code>mountain</code>. Your task is to find all the <strong>peaks</strong> in the <code>mountain</code> array.</p> <p>Return <em>an array that consists of </em>indices<!-- notionvc: c9879de8-88bd-43b0-8224-40c4bee71cd6 --><em> of <strong>peaks</strong> in the given a...
0
{ "code": "class Solution {\npublic:\n vector<int> findPeaks(vector<int>& mountain) {\n vector<int> ans;\n int n = mountain.size();\n\n for(int i = 1;i<n-1;i++){\n if(mountain[i-1] < mountain[i] && mountain[i] > mountain[i+1]){\n ans.push_back(i);\n }\n ...
3,221
<p>You are given a <strong>0-indexed</strong> array <code>mountain</code>. Your task is to find all the <strong>peaks</strong> in the <code>mountain</code> array.</p> <p>Return <em>an array that consists of </em>indices<!-- notionvc: c9879de8-88bd-43b0-8224-40c4bee71cd6 --><em> of <strong>peaks</strong> in the given a...
0
{ "code": "class Solution {\npublic:\n vector<int> findPeaks(vector<int>& nums) {\n int n = nums.size();\n vector<int> ans;\n if (n == 0) return ans; \n for (int i = 1; i < n - 1; i++) {\n if (nums[i] > nums[i - 1] && nums[i] > nums[i + 1]) {\n ans.push_back(i...
3,221
<p>You are given a <strong>0-indexed</strong> array <code>mountain</code>. Your task is to find all the <strong>peaks</strong> in the <code>mountain</code> array.</p> <p>Return <em>an array that consists of </em>indices<!-- notionvc: c9879de8-88bd-43b0-8224-40c4bee71cd6 --><em> of <strong>peaks</strong> in the given a...
0
{ "code": "class Solution {\npublic:\n vector<int> findPeaks(vector<int>& A) {\n int n = A.size();\n vector<int>ans;\n for(int i = 1; i < n-1; i++){\n if(A[i] > A[i-1] && A[i] > A[i+1]) ans.push_back(i);\n }\n return ans;\n }\n};", "memory": "24000" }
3,221
<p>You are given a <strong>0-indexed</strong> array <code>mountain</code>. Your task is to find all the <strong>peaks</strong> in the <code>mountain</code> array.</p> <p>Return <em>an array that consists of </em>indices<!-- notionvc: c9879de8-88bd-43b0-8224-40c4bee71cd6 --><em> of <strong>peaks</strong> in the given a...
0
{ "code": "class Solution\n{\npublic:\n vector<int> findPeaks(vector<int> &mountain)\n {\n vector<int> output;\n for (int i = 1; i < mountain.size() - 1; i++)\n {\n if (mountain[i] > mountain[i - 1] && mountain[i] > mountain[i + 1])\n {\n output.push_bac...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
0
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n // sort(coins.begin(),coins.end());\n const int n = target+1;\n bitset<100001> bt;//all are initially zero only\n bitset<100001> temp;\n for(int &c:coins){\n temp = bt;\n ...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
0
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n // sort(coins.begin(),coins.end());\n const int n = target+1;\n bitset<100001> bt;//all are initially zero only\n bitset<100001> temp;\n for(int &c:coins){\n temp = bt;\n ...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
0
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n ranges::sort(coins);\n\n int ans = 0;\n int cur_max = 0;\n int i = 0, n = coins.size();\n\n while(cur_max<target){\n if (i<n && coins[i]<=cur_max+1){\n cur_m...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
0
{ "code": "class Solution {\n public:\n // Same as 330. Patching Array\n int minimumAddedCoins(vector<int>& coins, int target) {\n int ans = 0;\n int i = 0; // coins' index\n long miss = 1; // the minimum sum in [1, n] we might miss\n\n ranges::sort(coins);\n\n while (miss <= target)\n if ...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
0
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n int i=0;\n int ans=0;\n int n=coins.size();\n sort(coins.begin(),coins.end());\n long long maxe=0;\n for(int i=0;i<n;i++){\n while(maxe<coins[i]-1){\n ...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
0
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n sort(coins.begin(), coins.end());\n\n long long reachable = 0;\n int minCoins = 0; \n\n for (int coin : coins) {\n if (coin > reachable + 1) {\n while (reachable + ...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
0
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n int add = 0;\n int obtainable = 0;\n sort(coins.begin(),coins.end());\n for(int coin: coins){\n while(coin > obtainable+1){\n add++;\n int newcoin = ...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
0
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n int obtainable =0;\n int coins_added=0;\n sort(coins.begin(),coins.end()); \n // Ex: coins = [1,4,10], target = 19\n for (int coin:coins)\n {\n while (coin > obtain...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
0
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n sort(coins.begin(), coins.end());\n\n long missed = 1;\n int addedCoins = 0;\n int idx = 0;\n while (missed <= target) {\n // If the current coin can help us reach 'missed'...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
1
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n int obtainable =0;\n int coins_added=0;\n sort(coins.begin(),coins.end());\n\n for (int coin:coins)\n {\n while (coin>obtainable+1){\n coins_added++;\n ...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
1
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n int obtainable =0;\n int coins_added=0;\n sort(coins.begin(),coins.end());\n\n for (int coin:coins)\n {\n while (coin > obtainable+1){\n coins_added++;\n ...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
3
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n int obtainable =0;\n int coins_added=0;\n sort(coins.begin(),coins.end());\n\n for (int coin:coins)\n {\n while (coin > obtainable+1){\n coins_added++;\n ...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
3
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n // n*(n+1) = 10\n // n2 + n - 10;\n // n = (-1 + sqrt(41) )/2;\n //1 ------- 4\n // 1 |2 3| 4\n // (-1 + sqrt())\n // x + x+1 + ........ + (x+k) = y\n // (k+1)*x + ...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
3
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n int ans = 0;\n stable_sort(coins.begin(),coins.end());\n int x = 1;\n int pos = 0;\n while(x<=target&&pos<coins.size()){\n if(coins[pos]>x){\n x*=2;\n ...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
3
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n int sum = 0;\n sort(coins.begin(),coins.end());\n queue<int> q1;\n int n = coins.size();\n for(int i = 0; i<n; i++)\n {\n q1.push(coins[i]);\n }\n\n in...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
3
{ "code": "// x is obtainable if there exists a sequence of coins sums to x\n// Return the min # of coins of any value that needed to be added to the array\n// s.t. every integer in [1, target] is obtainable\n\n// \n\nclass Solution\n{\npublic:\n int minimumAddedCoins(vector<int>& coins, int target)\n {\n ...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
3
{ "code": "// x is obtainable if there exists a sequence of coins sums to x\n// Return the min # of coins of any value that needed to be added to the array\n// s.t. every integer in [1, target] is obtainable\n\n// \n\nclass Solution\n{\npublic:\n int minimumAddedCoins(vector<int>& coins, int target)\n {\n ...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
3
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n sort(coins.begin(), coins.end());\n int result = 0;\n long long covered = 0;\n vector<int> exist(target+1, 0);\n for (int i = 0; i < coins.size(); i++) {\n while (covered <...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
3
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n vector<int> dp(target+1,0);\n dp[0]=1;\n sort(coins.begin(),coins.end());\n int n=coins.size();\n int cnt=0;\n int si=0,m=1;\n int i=1,maxi=0;\n while(i<=target){...
3,231
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p> <p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p> <p>Re...
3
{ "code": "class Solution {\npublic:\n int minimumAddedCoins(vector<int>& coins, int target) {\n sort(coins.begin(), coins.end());\n set<int> st;\n int curr=1;\n int sum=0;\n for(int i=0;i<coins.size();i++){\n while(coins[i]>curr){\n sum++;\n ...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
0
{ "code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums) {\n int allEvenCount=0;\n int allOddCount = 0;\n int n=nums.size();\n for(int i=0;i<n;i++){\n if(nums[i]%2==0)allEvenCount++;\n }\n for(int i=0;i<n;i++){\n if(nums[i]%2==1)all...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
0
{ "code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums) {\n int n = nums.size();\n int odd = 0;\n int even = 0;\n int odd_start = 0;\n int even_start = 0;\n for(auto c : nums){\n if(c%2){\n odd++;\n if(odd_start%...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "int speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\nclass Solution {\npublic:\n int maximumLength(vector<int>& nums) {\n vector<int> same(2,0);\n vector<int> diff(2,0);\n\n for(int i = 0 ;i< nums.size();i++){\n int curr = nums[i]%2;\n same[curr...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\n int solve(vector<int>& nums,int index,int prev,int rem) {\n if(index>=nums.size()) {\n return 0;\n }\n int include=0;\n int exclude=0;\n if(prev==-1 or((nums[index]+nums[prev])%2==rem) or rem==-1) {\n int tempRem;\n ...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums) \n {\n unordered_map<int,int> mp;\n for(int i=0;i<nums.size();i++)\n {\n mp[nums[i]%2]++;\n }\n int g=-1;\n for(auto x:mp)\n {\n if(g<x.second)\n {\n ...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums) {\n int n=nums.size();\n if(n==2) return 2;\n unordered_map<int,int>mpp;\n for(int i=0;i<nums.size();i++){\n if(nums[i]%2==0){\n mpp[0]++;\n nums[i]=0;\n }\n else{\n ...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums) {\n // f[k][i]: max length of subsequence ending at i\n // k = 0, odd-odd or even-even\n // k = 1, odd-even or even-odd\n int f[2][200010];\n int n = nums.size();\n memset(f[0], 0...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "int dp[200004][3];\nclass Solution {\npublic:\n int rec(int d, vector<int>&arr,int k)\n {\n unordered_map<int,int>mp;\n for(int i=0;i<arr.size();i++)\n {\n int ind=(d+k-arr[i])%k;\n if(mp.find(ind)!=mp.end())mp[arr[i]]=mp[ind]+1;\n else mp[arr[i]]...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\n int dp[200002][3];\n int maximumLength(vector<int>& nums) {\n memset(dp, -1, sizeof(dp));\n int odd=0, even=0;\n for(int it: nums){\n if(it%2) odd++;\n else even++;\n }\n // DP TC: O(N*2) SC: O(N*2) \n //return...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\n int maxlength = 0;\n int maximumLength(vector<int>& nums) {\n int even = 0, odd = 0,first_odd = -1,first_even=-1;\n for(int i = 0; i < nums.size(); i++)\n {\n if(nums[i]&1)\n { if(first_odd==-1)\n first_odd = i; \n ...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\n int odd(vector<int>& nums){\n int cnt = 0;\n for(auto it: nums){\n if(it%2) cnt++;\n }\n return cnt;\n }\n int even(vector<int>& nums){\n int cnt = 0;\n for(auto it: nums){\n if(it%2 == 0) cnt++;\n }...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums) {\n \n int oddCount = 0;\n int evenCount = 0;\n for(int i = 0;i<nums.size();i++){\n nums[i] = nums[i] % 2;\n if(nums[i] == 1){\n oddCount++;\n }else{\n ...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums) {\n int n = nums.size();\n int length_all_odd = 0;\n\n for(int i = 0; i<n; i++){\n if(nums[i]%2==1) length_all_odd++;\n }\n int length_all_even = 0;\n for(int i = 0; i<n; i++){\n ...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums) {\n int max_length = 0;\n int n = nums.size();\n vector<pair<int,int>> dp_array(n, make_pair(1,1));\n \n int odd = 0;\n int even = 0;\n int both = 0;\n int c = nums[0]%2;\n\n for(int i=0;i<nums.size();i+...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\n int sameSet(vector<int> nums)\n {\n int countEven=0, countOdd =0;\n for( int i: nums)\n {\n if(i%2==0)countEven++;\n else countOdd++;\n }\n return max(countEven, countOdd);\n }\n int alternateSet(vector<int> nu...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\n int alternatingParitySubsequence(vector<int> nums, int startingNumberParity) {\n int currentNumberParity = startingNumberParity;\n int len = 0;\n for(auto num: nums) {\n if((num % 2) == currentNumberParity) {\n len++;\n ...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums) {\n \n int n = nums.size();\n \n vector<int>oidx(n,n);\n vector<int>eidx(n,n);\n \n int o = -1;\n int e = -1;\n if(nums[n-1]%2==1) o = n-1;\n if(nums[n-1]%2==0) e = n-1;...
3,490
You are given an integer array <code>nums</code>. <p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p> <ul> <li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + ...
3
{ "code": "class Solution {\npublic:\nint solve(vector<int>& nums, int a,int b){\n int i=0;\n int f=0;\n int c=0;\n while(i<nums.size()){\n if((f==0&&nums[i]==a)||(f==1&&nums[i]==b)){\n c++;\n f=f^1;\n }\n i++;\n }\n ...