id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\n bool check(string &s, int len){\n int n = s.size();\n unordered_set<string> st;\n for(int i = 0; i < n; i += len){\n string anagram = s.substr(i, len);\n sort(anagram.begin(), anagram.end());\n st.insert(anagram);\n }\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int len=s.length();\n int ans=len;\n for(int i=1;i<=len;i++){\n set<string> st;\n if(len%i==0){\n cout<<\"hello\";\n for(int j=0;j<len;j=j+i){\n stri...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n=s.size();\n // cout<<\"ji\";\n for(int i=1;i<=n;i++)\n {\n if(n%i)continue;\n set<string>st;\n int j=0;\n while(j<n)\n {\n string temp=s....
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n for(int i=1;i<=s.size();i++){\n if(s.size()%i == 0){\n map<string,int>mp;\n for(int j =0;j<s.size();j+=i){\n string jj = s.substr(j,i);\n sort(jj.begin(),jj.end());\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\npublic:\n bool equalStrings(string s, int p){\n bool flag = false;\n string temp;\n for(int i=0;i<s.length();i+=p){\n string t=\"\";\n for(int j=i;j<i+p;j++){\n t += s[j];\n }\n cout<<t<<endl;\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\npublic:\n bool equalStrings(string s, int p){\n bool flag = false;\n string temp;\n for(int i=0;i<s.length();i+=p){\n string t=\"\";\n for(int j=i;j<i+p;j++){\n t += s[j];\n }\n cout<<t<<endl;\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n = s.length();\n int ans = INT_MAX;\n\n for (int len = 1; len <= n; len++) {\n if (n % len == 0) {\n set<string> sett;\n\n for (int j = 0; j < n; j += len) {\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int size = s.length();\n int ans = size;\n\n for(int i=1 ; i<=size ; i++){\n if(size % i == 0){\n set<string> st;\n for(int j=0 ; j<size ; j+=i){\n string temp...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n = s.size();\n int ans = n;\n\n for(int i=1;i<=n;i++){\n set<string> st;\n\n if(n%i == 0){\n for(int j=0;j<n;j=j+i){\n string temp = s.substr(j, i);\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int size = s.length();\n int ans = size;\n for(int i=1;i<=size;i++){\n set<string>st;\n if(size%i==0){//condition for possible length\n for(int j=0;j<size;j+=i){\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int l=s.size(),i=0,j;\n vector<int> f(26,0);\n\n while(true){\n f[s[i]-'a']++;\n if(i>=l/2)return l;\n\n j=i+1;\n vector<int> sf(26,0);\n int flag;\n\n if...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution{\npublic:\n int minAnagramLength(string s){\n int n = s.size(),ans=n;\n for(int i=2;i<=n;i++){\n if(n % i!=0)continue;\n int k=n/i,j=i-1;\n unordered_map<char,int>mp;\n for(int m=0;m<k; m++){\n mp[s[m]]++;\n }unordered_map<char,int>mp2;\n int l=k;\n while(l<n...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\npublic:\n \n bool check(string s, unordered_map<string, int>& mp, int len) {\n mp.clear();\n for (int i = 0; i <= s.size() - len; i += len) {\n string t = s.substr(i, len);\n sort(t.begin(), t.end());\n mp[t]++;\n }\n \n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\nprivate:\n bool isAnagram(string s, string t) {\n vector<int> mp(26, 0);\n\n for (char ch: s) {\n mp[ch - 'a']++;\n }\n\n for (char ch: t) {\n mp[ch - 'a']--;\n }\n\n for (int n : mp) {\n if (n != 0) return fals...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
1
{ "code": "class Solution {\npublic:\n bool isValid(string &s, int k, int &n){\n map<char, int> m;\n for(int i=0; i<k; i++) m[s[i]]++;\n\n for(int i=k; i<n; i+=k){\n map<char, int> temp;\n\n for(int j=i; j<i+k; j++) temp[s[j]]++;\n if(temp != m) return 0;\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic: \n int minAnagramLength(string s) {\n map<char,int>mpp;\n \n \n for(int i=1;i<=s.size()/2;i++){\n mpp[s[i-1]]++;\n if( s.size()%i!=0)\n continue;\n int f=-1;\n for(int p=0;p<s.size();p+=i){\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic: \n int minAnagramLength(string s) {\n map<char,int>mpp;\n \n \n for(int i=1;i<=s.size()/2;i++){\n mpp[s[i-1]]++;\n if( s.size()%i!=0)\n continue;\n int f=-1;\n for(int p=0;p<s.size();p+=i){\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n=s.size();\n int mn=INT_MAX;\n \n map<char,int> mp;\n for(int i=0;i<n;i++){\n mp[s[i]]++;\n if(n%(i+1)==0){\n cout<<\" i \"<<i+1<<endl;\n bool f=true...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n \n vector<int>allfactors(int n){\n vector<int>ans;\n for(int i=1;i<=sqrt(n);i++){\n if(n%i==0){\n ans.push_back(i);\n if(n/i!=i){\n\n ans.push_back(n/i);\n }\n }\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n = s.length();\n int ans = 1e9;\n for (int i = 1; i * i <= n; i++) {\n if (n % i == 0) {\n int len = i;\n map<char, int> m;\n for (int j = 0; j < i; j++) {\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n string str=\"\";\n string temp;\n int ptr,n;\n n = s.size();\n ptr=0;\n int dummy=0;\n map<char,int>mp;\n while(ptr<n){\n dummy = 0;\n str+=s[ptr];\n \n //map<char,int>mp;\n...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n\nbool ok(string s, int len){\n int n = s.size();\n map<char,int>mp;\n for(int i=0; i<len; i++){\n mp[s[i]]++;\n }\n for(int i=len; i<n; i+=len){\n map<char,int>m;\n for(int j=i; j<len+i; j++){\n m[s[j]]++;\n }\n if (m != mp) return false; ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n bool isok(int k, string s) {\n map<char, int> mp;\n int n = s.size();\n \n for (int i = 0; i < k; i++) {\n mp[s[i]]++;\n }\n for (int i = 0; i < n; i+=k) {\n map<char, int> ss;\n for (int j = i; j < i + k...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n int minimumOperationsToMakeKPeriodic(string word, int k) {\n string r=\"\";\n unordered_map<string,int> mp;\n int n=word.size();\n for(int i=0;i<n;i+=k){\n // if(i+k-1<n){\n\n string s=word.substr(i,k);\n sort(s.begin(),s.end())...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n\n bool check(int sz, string &s) {\n unordered_map<int,int> ump;\n for(int i = 0; i < sz; i++) ump[s[i]-'a']++;\n for(int i = sz ; i < s.size(); i += sz) {\n unordered_map<int,int> temp;\n for(int j = i; j < i + sz; j++) {\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n int minAnagramLength(const string& str) {\n vector<vector<int>> cv(26, vector<int>(str.size() + 1, 0));\n for (int i = 0; i < str.size(); ++i) {\n cv[str[i] - 'a'][i + 1] = 1;\n }\n for (auto& vec : cv) {\n for (int i = 1; i <...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n = s.size() ; \n vector<vector<int>> freq(26 , vector<int>(n+1 , 0)) ; \n for(int i = 0 ; i < n ; i++){\n freq[s[i]-'a'][i+1] = 1 ;\n for(int j = 0 ; j < 26 ; j++){\n freq[j][i+1...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n = s.size() ; \n vector<vector<int>> freq(26 , vector<int>(n+1 , 0)) ; \n for(int i = 0 ; i < n ; i++){\n freq[s[i]-'a'][i+1] = 1 ;\n for(int j = 0 ; j < 26 ; j++){\n freq[j][i+1...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\n bool ok(const std::string& s, int k) {\n int n = s.length();\n std::vector<int> cnt(26, 0);\n\n for (int i = 0; i < k; i++) {\n cnt[s[i] - 'a']++;\n }\n\n for (int i = k; i < n; i += k) {\n std::vector<int> cnt2(26, 0);\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\n bool ok(const std::string& s, int k) {\n int n = s.length();\n std::vector<int> cnt(26, 0);\n\n for (int i = 0; i < k; i++) {\n cnt[s[i] - 'a']++;\n }\n\n for (int i = k; i < n; i += k) {\n std::vector<int> cnt2(26, 0);\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n bool check(string& s,int mid){\n vector<int> v1(26,0);\n int n=s.size();\n for(int i=0;i<mid;i++){\n v1[int(s[i])-97]+=1;\n }\n for(int i=mid;i<s.size();i++){\n int g=i;\n vector<int> v(26,0);\n if...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n=s.size();\n vector <int> factors;\n for(int i=1;i<=n;i++) {\n if(!(n%i)) factors.push_back(i);\n }\n int size=factors.size();\n for(int i=0;i<size;i++) {\n vector <int> se...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n vector<int> getFreq(auto b, auto e) {\n vector<int> freq(26, 0);\n for (auto it = b; it != e; it++) {\n freq[*it - 'a']++;\n }\n return freq;\n }\n\n int minAnagramLength(string s) {\n const int sz = s.size();\n for (...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n = s.length();\n int k = s.length();\n int ans=INT_MAX;\n for(int i=k;i>=1;i--){\n if(n%i!=0) continue;\n string init = s.substr(0,i);\n map<int,int> mi;\n for(int ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n unordered_map<char, int> umap; \n int distinct = 0; \n for (char x : s) {\n if (umap[x]++ == 0) {\n distinct++;\n }\n } \n int length = s.length();\n for (int i ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n \n int f(vector<vector<int>>&pre, string s, int i){\n int j = i;\n while(j<=s.size()){\n for(int k=0;k<26;k++){\n if(pre[k][j] - pre[k][j-i] != pre[k][i]-pre[k][0])return 0;\n }\n j+=i;\n }\n retur...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n= s.size();\n vector<int> factors;\n vector<int> finalf(26,0);\n \n if(n==1)\n return 1;\n \n for(int i=1;i*i<=n;i++)\n if (n%i == 0){\n factors.push...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n bool isPrime(int N) {\n if (N <= 1) {\n return false;\n }\n\n for (int i = 2; i < N; i++) {\n if (N % i == 0) {\n return false;\n }\n }\n return true;\n }\n\n bool check(string s, int k){...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution \n{\npublic:\n vector<int> divisors(int n)\n {\n vector<int> v;\n for (int i=1; i<=sqrt(n); i++) \n {\n if (n%i==0) \n {\n if (n/i==i) v.push_back(i);\n else \n {\n v.push_back(i)...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "\nclass Solution {\npublic:\n int minAnagramLength(string s) {\n int n = s.length();\n int ans = n; // Default to the maximum possible length, which is the length of the string itself.\n\n // Iterate over all divisors of n\n for (int len = 1; len <= n; ++len) {\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <string>\n\nclass Solution {\npublic:\n\n bool areAnagrams(string& s1, string& s2) {\n vector<int> freq(26, 0); // frequency array for letters a-z\n\n // Count frequencies for the first string\n for (char c : s1)...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n bool isValid(int div, string s, int n) {\n vector<int> need(26);\n for (int j = 0; j < div; j++) {\n need[s[j] - 'a']++;\n }\n bool flag = true;\n for (int j = div; j < n; j += div) {\n vector<int> temp(26);\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
2
{ "code": "class Solution {\npublic:\n bool isValid(int div, string s, int n) {\n vector<int> need(26);\n for (int j = 0; j < div; j++) {\n need[s[j] - 'a']++;\n }\n bool flag = true;\n for (int j = div; j < n; j += div) {\n vector<int> temp(26);\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n = s.length(), ans = n;\n \n auto check = [&] (int m) {\n vector<int> req(26);\n for (int i = 0; i < m; i++) req[s[i] - 'a']++;\n for (int i = m; i < n; i += m) {\n ve...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n vector<int> factors(int n){\n vector<int> ans;\n for(int i = 1 ; i <= sqrt(n) ; i++){\n if(n%i == 0){\n ans.push_back(i);\n if(n/i != i) ans.push_back(n/i);\n }\n }\n return ans;\n }\n int m...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "// Time: O(sqrt(n) * n + (26 * sum(n/i for i in range(1, n+1) if n%i == 0))) < O(sqrt(n) * n + 26 * sum(n/i for i in range(1, n+1)) = O(sqrt(n) * n + 26 * nlogn)\n// Space: O(26)\n\n// number theory, freq table\nclass Solution {\npublic:\n int minAnagramLength(string s) {\n const auto& check = [...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\n\nprivate:\n\nbool check(int m, string &s){\n\n vector<int> occ(26,0);\n for(int i = 0; i < m; i++) occ[s[i] - 'a']++;\n int i = m;\n while(i < s.size()){\n\n int j = i;\n vector<int> tempocc(26,0);\n while(j < i+m){\n tempocc[s[j] - 'a']++;\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\nbool isvalid(int l , string &s){\n if(s.length()%l != 0){\n return false ;\n }\n vector<int> arr(26,0) ;\n for(int i=0 ; i<l ; i++){\n arr[s[i]-'a']++ ;\n }\n for(int i=l ; i<=s.length()-l ; ){\n vector<int> temp(26,0) ;\n for(int j=i...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n bool check(int len, string &s) {\n vector<int> a(26, 0);\n for(int i = 0; i < len; i++) {\n a[s[i]-'a']++;\n }\n\n for(int i = 0; i < s.size(); i += len) {\n vector<int> b(26, 0);\n for(int j = i; j < i+len; j++) {\...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n bool isAnagram(string s1,string s2){\n if(s1.length()!=s2.length()){\n return false;\n }\n vector<int> freq(26,0);\n for(auto c:s1){\n freq[c - 'a']++;\n }\n for(auto c:s2){\n freq[c - 'a']--;\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\nprivate:\n bool solve(string& s, int window)\n {\n //cout << \"window = \" << window << endl;\n unordered_map<int, int> cnt;\n for (int i = 0; i < window; ++i)\n {\n cnt[s[i]-'a']++;\n }\n for (int i = window; i < s.size(); i += w...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n bool check(const string& s, int n) {\n unordered_map<char, int> mp;\n for (int i = 0; i < n; ++i) {\n mp[s[i]]++;\n }\n for (int i = n; i < s.size(); i += n) {\n unordered_map<char, int> match;\n for (int j = i; j <...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n bool check(string& s, int n) {\n unordered_map<char, int> mp;\n for (int i = 0; i < n ; ++i) mp[s[i]]++;\n\n for (int i = n; i < s.size(); i += n) {\n unordered_map<char, int> mp2;\n for (int j = i+n-1; j >= i; --j) mp2[s[j]]++;\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n bool areAnagrams(unordered_map<char, int>& freq1,\n unordered_map<char, int>& freq2) {\n return freq1 == freq2;\n }\n\n int minAnagramLength(string input_str) {\n int n = input_str.length();\n\n // Find all divisors of n\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\n private:\n bool isValid(string &s,int idx){\n unordered_map<char,int>mp;\n int n = s.size();\n for(int i=0;i<idx;i++){\n char ch = s[i];\n mp[ch]++;\n }\n for(int i=idx;i<n;i += idx){\n unordered_map<char,int>match...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n bool isOk(string& s, int n) {\n unordered_map<char, int> mp;\n for (int i = 0; i < n; i++) {\n mp[s[i]]++;\n }\n for (int i = n; i < s.size(); i += n) {\n unordered_map<char, int> match;\n for (int j = i; j < i + n;...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "#include <vector>\n#include <string>\n#include <unordered_map>\n\nclass Solution {\npublic:\n bool isAnagram(const std::string& s1, const std::string& s2) {\n if (s1.size() != s2.size()) return false;\n\n std::unordered_map<char, int> count;\n for (char c : s1) count[c]++;\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n bool f(int len, string s, int n, unordered_map<char, int>& mp1) {\n // cout<<len<<\"\"\n int num = len;\n int i;\n for ( i = len; i <= n - num; i += num) {\n unordered_map<char, int> mp;\n int k = i + num;\n if (k >...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n bool check(string s,int m){\n cout<<m<<endl;\n unordered_map<char,int>Map;\n for(int j=0;j<m;j++)\n Map[s[j]]++;\n for(int i=m;i<s.size();i+=m){\n unordered_map<char,int>map;\n for(int j=0;i+j<s.size() && j<m ;j++)\...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\nbool check(string s,int n){\n unordered_map<char,int>mp;\n for(int i=0;i<n;i++){\n mp[s[i]]++;\n }\n for(int j=n;j<s.size();j+=n){\n unordered_map<char,int>match;\n for(int k=j;k<j+n;k++){\n match[s[k]]++;\n }\n if(match!=mp) ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "\n\nclass Solution {\npublic:\n bool helper(int k, string s, int n) {\n unordered_map<char, int> mp;\n for (int i = 0; i < k; i++) {\n mp[s[i]]++;\n }\n for (int i = k; i < n; i = i + k) {\n unordered_map<char, int> mp1;\n int p = k;\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n bool check(string s,int n){\n unordered_map<char,int> m;\n for(int i=0;i<n;i++){\n m[s[i]]++;\n }\n for(int i=n;i<s.length();i+=n){\n unordered_map<char,int> m1;\n for(int j=i;j<i+n;j++){\n m1[s[j]]++...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n bool check(string s,int l)\n {\n unordered_map<char,int>mp;\n for(int i=0;i<l;i++)mp[s[i]]++;\n \n for(int i=l;i<s.size();i+=l)\n {\n unordered_map<char,int>match;\n for(int j=i;j<i+l;j++)match[s[j]]++;\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n bool helper(int k, string s) {\n unordered_map<char, int> mp;\n for (int i = 0; i < k; i++) {\n mp[s[i]]++;\n }\n for (int i = k; i < s.length(); i = i + k) {\n unordered_map<char, int> mp1;\n int p = k;\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) \n {\n\n vector<vector<int>>len(s.size(),vector<int>(26,0));\n \n\n for(int i=0;i<s.size();i++)\n {\n \n len[i][s[i]-97]++;\n\n \n \n\n\n }\n\n for(int j=0;j<26...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n = s.size();\n vector<vector<int>> prefix(n + 1, vector<int>(26, 0));\n\n for (int i = 0; i < n; ++i) {\n prefix[i + 1] = prefix[i];\n ++prefix[i + 1][s[i] - 'a'];\n }\n\n for (in...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "\n\n// COPY ALL MACROS BELOW\n\ntypedef long long LL;\n#define MP make_pair\n#define PB push_back\n#define F first\n#define S second\n#define LB lower_bound\n#define UB upper_bound\n#define SZ(x) ((int)x.size())\n#define LEN(x) ((int)x.length())\n#define ALL(x) begin(x), end(x)\n#define RSZ resize\n#define...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n=s.length();\n int l=0,r=n+1;\n vector<vector<int>>pre(n+1,vector<int>(26));\n for(int i=0;i<n;i++){\n for(int j=0;j<26;j++){\n pre[i+1][j]=pre[i][j]+(s[i]-'a'==j);\n }\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n int n=s.size();\n map<char,int>mpp;\n for(int i=0;i<n;i++){\n mpp[s[i]]++;\n }\n //cout<<mpp.size()<<endl;\n if(mpp.size()==1)return 1;\n int res=n;\n for(int j=2;j*j<=n;j++)...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n std::vector<size_t> counts[26];\n for (auto &v : counts) {\n v.resize(s.size() + 1);\n }\n\n for (size_t i = 0; i < s.size(); i++) {\n counts[s[i] - 'a'][i + 1] = 1;\n }\n for (auto &v : counts) {\n for (size_t...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n map<char,int> m,m1;\n int n=s.length();\n for(int i=0;i<s.length();i++){\n m[s[i]]++;\n if(n%(i+1)==0){\n \n int b=0;\n for(int h=0;h<n/(i+1)-1;h++){\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n int minAnagramLength(string s) {\n map<char,int> m,m1;\n int n=s.length();\n for(int i=0;i<s.length();i++){\n m[s[i]]++;\n if(n%(i+1)==0){\n \n int b=0;\n for(int h=0;h<n/(i+1)-1;h++){\n ...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define lli long long\n#define endl '\\n'\n#define loop(i, n) for (int i = 0; i < n; i++)\n#define pool(i, n) for (int i = n - 1; i >= 0; i--)\n#define rep(i, a, b) for (int i = a; i <= b; i++)\n#define per(i, b, a) for (int i = b; i >= a; i--)\n#define all...
3,395
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p> <p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p> <p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For e...
3
{ "code": "class Solution {\npublic:\n bool isAnagram(string a, string b){\n sort(a.begin(), a.end());\n sort(b.begin(), b.end());\n\n return a == b;\n }\n\n bool check(string s, int k){\n vector<string> result;\n for (int i = 0; i < s.length(); i += k) {\n resul...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
0
{ "code": "class Solution {\npublic:\n int minCostToEqualizeArray(vector<int>& nums, int cost1, int cost2) \n {\n int mod = 1000000007;\n long long int n = nums.size();\n\n long long int max_element{LLONG_MIN};\n\n for(int i{}; i< nums.size();i++)\n {\n max_element = max(ma...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
0
{ "code": "#define ll long long\nclass Solution {\npublic:\n int mod = 1e9 + 7;\n ll sum = 0;\n ll mini = 1e8;\n\n ll ankit( vector<int> &nums, ll cost1, ll cost2, ll maxii ){\n \n \n ll maxi = maxii - mini;\n \n ll n = nums.size();\n\n ll total = maxii*n - sum;\n\...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
0
{ "code": "class Solution {\npublic:\n int minCostToEqualizeArray(vector<int>& nums, int cost1, int cost2) {\n long long sum = 0;\n long long mi = 100000009;\n long long ma = 0;\n long long mod = 1000000007;\n \n\n for(long long x: nums) {\n sum += x;\n ...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
0
{ "code": "class Solution {\npublic:\n int minCostToEqualizeArray(vector<int>& nums, int cost1, int cost2) \n {\n int mod = 1000000007;\n long long int n = nums.size();\n\n long long int max_element{LLONG_MIN};\n\n for(int i{}; i< nums.size();i++)\n {\n max_element = max(ma...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
2
{ "code": "class Solution {\npublic:\n int minCostToEqualizeArray(vector<int>& nums, int singleIncrementCost, int pairIncrementCost) {\n long long numElements = nums.size();\n long long maximumElement = 0, totalSum = 0, minimumElement = 1e9;\n long long modulo = 1e9 + 7;\n\n // calculat...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
2
{ "code": "class Solution {\npublic:\n int minCostToEqualizeArray(vector<int>& nums, int singleIncrementCost, int pairIncrementCost) {\n long long numElements = nums.size();\n long long maximumElement = 0, totalSum = 0, minimumElement = 1e9;\n long long modulo = 1e9 + 7;\n\n // calculat...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
3
{ "code": "static auto fastio = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\nclass Solution {\npublic:\n int minCostToEqualizeArray(vector<int>& A, int c1, int c2) {\n int ma = *max_element(A.begin(), A.end());\n int mi = ...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
3
{ "code": "static auto fastio = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\nclass Solution {\npublic:\n int minCostToEqualizeArray(vector<int>& A, int c1, int c2) {\n int ma = *max_element(A.begin(), A.end());\n int mi = ...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
3
{ "code": "static auto fastio = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n int minCostToEqualizeArray(vector<int>& A, int c1, int c2) {\n int n = A.size(), mod = 1000000007;\n long long tota...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
3
{ "code": "using LL = long long;\nclass Solution {\n int mod = 1e9+7;\n LL total;\npublic:\n int minCostToEqualizeArray(vector<int>& nums, int cost1, int cost2) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n LL cost = LLONG_MAX;\n cost2 = min(2*cost1, cost2);\n ...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
3
{ "code": "int MOD = 1000000007;\ntypedef long long int ll;\n\nll solve(ll su, ll su1, int cost1, int cost2) {\n if (cost1 * 2 < cost2) return su * cost1;\n ll claim = min(su1, su/2);\n return claim * cost2 + (su - claim * 2) * cost1;\n}\n\nclass Solution {\npublic:\n int minCostToEqualizeArray(vector<int...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
3
{ "code": "int MOD = 1000000007;\ntypedef long long int ll;\n\nll solve(ll su, ll su1, int cost1, int cost2) {\n if (cost1 * 2 < cost2) return su * cost1;\n ll claim = min(su1, su/2);\n return claim * cost2 + (su - claim * 2) * cost1;\n}\n\nclass Solution {\npublic:\n int minCostToEqualizeArray(vector<int...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
3
{ "code": "static auto fastio = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\nusing LL = long long;\nLL M = 1e9+7;\nclass Solution {\npublic:\n int minCostToEqualizeArray(vector<int>& nums, int cost1, int cost2) \n {\n int n = ...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
3
{ "code": "using LL = long long;\nLL M = 1e9+7;\nclass Solution {\npublic:\n int minCostToEqualizeArray(vector<int>& nums, int cost1, int cost2) \n {\n std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout.tie(nullptr);\n int n = nums.size();\n sort(nums.begin(), nums.end());\n ...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n// using namespace __gnu_pbds;\n #define vb vector<bool>\n #define ff first\n #define ss second\n #define pb push_back\n #define gout(tno) cout << \"Case #\" << tno++ <<\": \"\n #define ld long double\n #define ll long lo...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
3
{ "code": "class Solution {\n #define endl \"\\n\"\n \n typedef long long ll;\n typedef long double ld;\n typedef vector<int> vi;\n typedef pair<int, int> pi;\n typedef pair<ll, ll> pll;\n typedef vector<ll> vll;\n typedef vector<pi> vpi;\n typedef vector<pll> vpll;\n typedef vector<v...
3,402
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p> <ul> <li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</...
3
{ "code": "#include <iostream>\n#include <utility>\n#include <vector>\n#include <algorithm>\n#include <numeric>\n#include <map>\n#include <unordered_set>\n#include <unordered_map>\n#include <queue>\n#include <set>\n#include <stack>\n#include <fstream>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tre...
3,415
<p>You are given a 2D matrix <code>grid</code> of size <code>m x n</code>. You need to check if each cell <code>grid[i][j]</code> is:</p> <ul> <li>Equal to the cell below it, i.e. <code>grid[i][j] == grid[i + 1][j]</code> (if it exists).</li> <li>Different from the cell to its right, i.e. <code>grid[i][j] != grid[i]...
0
{ "code": "class Solution {\npublic:\n bool satisfiesConditions(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n \n for(int j=0; j<m-1; j++){\n if(grid[0][j] == grid[0][j+1]) return false;\n }\n \n for(int i=1;i<n;i++){\n ...
3,415
<p>You are given a 2D matrix <code>grid</code> of size <code>m x n</code>. You need to check if each cell <code>grid[i][j]</code> is:</p> <ul> <li>Equal to the cell below it, i.e. <code>grid[i][j] == grid[i + 1][j]</code> (if it exists).</li> <li>Different from the cell to its right, i.e. <code>grid[i][j] != grid[i]...
0
{ "code": "#include <vector>\nusing namespace std;\nclass Solution {\n public:\n bool satisfiesConditions(vector<vector<int>>& grid) {\n for (size_t j = 1; j < grid.front().size(); ++j)\n if (grid[0][j] == grid[0][j - 1]) return false;\n\n for (size_t j = 0; j < grid.front().size(); ++j)\n for (size_...
3,415
<p>You are given a 2D matrix <code>grid</code> of size <code>m x n</code>. You need to check if each cell <code>grid[i][j]</code> is:</p> <ul> <li>Equal to the cell below it, i.e. <code>grid[i][j] == grid[i + 1][j]</code> (if it exists).</li> <li>Different from the cell to its right, i.e. <code>grid[i][j] != grid[i]...
0
{ "code": "class Solution {\npublic:\n bool satisfiesConditions(vector<vector<int>>& grid) {\n int n = grid.size() , m = grid[0].size() ;\n // if(n==1 && m==1) return true ;\n // if(n == 1 || m == 1) return false ;\n for(int i=0 ; i<n ; i++) {\n for(int j=0 ; j<m ; j++) {\n ...
3,415
<p>You are given a 2D matrix <code>grid</code> of size <code>m x n</code>. You need to check if each cell <code>grid[i][j]</code> is:</p> <ul> <li>Equal to the cell below it, i.e. <code>grid[i][j] == grid[i + 1][j]</code> (if it exists).</li> <li>Different from the cell to its right, i.e. <code>grid[i][j] != grid[i]...
0
{ "code": "class Solution {\npublic:\n bool satisfiesConditions(vector<vector<int>>& grid) {\n for (int i = 0; i < grid.size(); ++i) {\n for (int j = 0; j < grid[0].size(); ++j) {\n if (i + 1 < grid.size() && grid[i][j] != grid[i + 1][j]) {\n return false;\n ...
3,415
<p>You are given a 2D matrix <code>grid</code> of size <code>m x n</code>. You need to check if each cell <code>grid[i][j]</code> is:</p> <ul> <li>Equal to the cell below it, i.e. <code>grid[i][j] == grid[i + 1][j]</code> (if it exists).</li> <li>Different from the cell to its right, i.e. <code>grid[i][j] != grid[i]...
0
{ "code": "class Solution {\npublic:\n bool satisfiesConditions(vector<vector<int>>& grid) {\n int r = grid.size();\n int c = grid[0].size();\n\n for(int i = 0;i<r;i++){\n for(int j = 0;j<c;j++){\n if(i+1 != r && grid[i][j] != grid[i+1][j]) return false;\n ...
3,415
<p>You are given a 2D matrix <code>grid</code> of size <code>m x n</code>. You need to check if each cell <code>grid[i][j]</code> is:</p> <ul> <li>Equal to the cell below it, i.e. <code>grid[i][j] == grid[i + 1][j]</code> (if it exists).</li> <li>Different from the cell to its right, i.e. <code>grid[i][j] != grid[i]...
0
{ "code": "class Solution {\npublic:\n bool satisfiesConditions(vector<vector<int>>& a) {\n int i, j, m = a.size(), n = a[0].size();\n for (i = 0; i < m; ++i)\n for (j = 0; j < n; ++j){\n if (j + 1 < n && a[i][j] == a[i][j + 1]) return false;\n if (i + 1 < m &...
3,415
<p>You are given a 2D matrix <code>grid</code> of size <code>m x n</code>. You need to check if each cell <code>grid[i][j]</code> is:</p> <ul> <li>Equal to the cell below it, i.e. <code>grid[i][j] == grid[i + 1][j]</code> (if it exists).</li> <li>Different from the cell to its right, i.e. <code>grid[i][j] != grid[i]...
0
{ "code": "class Solution {\npublic:\n bool satisfiesConditions(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n\n // Case for 1x1 grid\n if (n == 1 && m == 1) {\n return true;\n }\n\n // Case for single row\n if (n == 1) {\...
3,415
<p>You are given a 2D matrix <code>grid</code> of size <code>m x n</code>. You need to check if each cell <code>grid[i][j]</code> is:</p> <ul> <li>Equal to the cell below it, i.e. <code>grid[i][j] == grid[i + 1][j]</code> (if it exists).</li> <li>Different from the cell to its right, i.e. <code>grid[i][j] != grid[i]...
0
{ "code": "class Solution {\npublic:\n bool satisfiesConditions(vector<vector<int>>& grid) {\n int row= grid.size();\n int col=grid[0].size();\n for(int i=0;i+1<row;i++){\n for(int j=0;j<col;j++){\n if(grid[i][j]!=grid[i+1][j]) return false;\n }\n }\...
3,419
<p>You are given a 2D<strong> </strong>array <code>points</code> and a string <code>s</code> where, <code>points[i]</code> represents the coordinates of point <code>i</code>, and <code>s[i]</code> represents the <strong>tag</strong> of point <code>i</code>.</p> <p>A <strong>valid</strong> square is a square centered a...
0
{ "code": "#pragma GCC optimize(\"O3, unroll-loops\")\n#pragma GCC target(\"avx2, bmi, bmi2, lzcnt, popcnt\")\n\nstatic auto _ = []() { \n cin.tie(nullptr) -> ios_base::sync_with_stdio(false); \n return nullptr; \n} ();\n\nclass Solution {\npublic:\n int maxPointsInsideSquare(vector<vector<int>>& ps, const s...