id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
0
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n int key = 0;\n int i = 0;\n while (num1 > 0 || num2 > 0 || num3 > 0) {\n int r1 = num1 % 10;\n int r2 = num2 % 10;\n int r3 = num3 % 10;\n int m1 = min(r1, r2);\...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) \n {\n int d1 = min({num1/1000, num2/1000, num3/1000});\n int d2 = min({num1/100%10, num2/100%10, num3/100%10});\n int d3 = min({num1/10%10, num2/10%10, num3/10%10});\n int d4 = min({num1%10, num2%10...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n \n vector<int> v1(4,0);\n vector<int> v2(4,0);\n vector<int> v3(4,0);\n\n for(int i=3;i>=0;i--)\n {\n v1[i]=num1%10;\n v2[i]=num2%10;\n v3[i]= num3%10;...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution \n{\npublic:\n int generateKey(int num1, int num2, int num3) \n {\n vector<int>a(4,0);\n vector<int>b(4,0);\n vector<int>c(4,0);\n int i = 0,j;\n while(num1>0)\n {\n j = num1%10;\n num1 = num1/10;\n a[i] = j;\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string s1=to_string(num1);\n string s2=to_string(num2);\n string s3=to_string(num3);\n int l=s1.size();\n int m=s2.size();\n int n=s3.size();\n for(int i=0;i<4-l;i++){\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n\n void f(vector<int>&a,int num1){\n int i=3;\n while(i>=0 && num1>0){\n a[i]=num1%10;\n num1=num1/10;\n i--;\n } \n }\n int generateKey(int num1, int num2, int num3) {\n vector<int>a(4,0);\n vector<int>...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n vector<int> ans;\n while(num1 != 0 || num2 != 0 || num3 != 0){\n vector<int> lasts;\n lasts.push_back(num1 % 10);\n lasts.push_back(num2 % 10);\n lasts.push_back(num3 %...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string s1=to_string(num1);\n string s2=to_string(num2);\n string s3=to_string(num3);\n int l=s1.size();\n int m=s2.size();\n int n=s3.size();\n for(int i=0;i<4-l;i++){\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n const string st1 = cov(num1, 4);\n const string st2 = cov(num2, 4);\n const string st3 = cov(num3, 4);\n\n string ans; // Changed to mutable string\n\n for (int i = 0; i < 4; i++) {\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string n1 = to_string(num1);\n while(n1.length() < 4){\n n1 = '0' + n1;\n }\n string n2 = to_string(num2);\n while(n2.length() < 4){\n n2 = '0' + n2;\n }\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string n1 = to_string(num1);\n while(n1.length() < 4){\n n1 = '0' + n1;\n }\n string n2 = to_string(num2);\n while(n2.length() < 4){\n n2 = '0' + n2;\n }\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string sNum1 = to_string(num1);\n string sNum2 = to_string(num2);\n string sNum3 = to_string(num3);\n\n while(sNum1.length() < 4) { sNum1 = \"0\" + sNum1;}\n while(sNum2.length() < 4) { sNum2...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "\nclass Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n // Convert numbers to strings with padding\n string str1 = to_string(num1);\n string str2 = to_string(num2);\n string str3 = to_string(num3);\n \n // Pad with leading zeros to ensure...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string s1 = to_string(num1);\n string s2 = to_string(num2);\n string s3 = to_string(num3);\n \n int maxilen = max(s1.length(), max(s2.length(), s3.length()));\n \n \n s1.i...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n void fillgap(string &s){\n int n = s.size();\n\n if(n < 4){\n s.insert(0, 4 - n, '0');\n }\n\n }\n int generateKey(int num1, int num2, int num3) {\n \n // change nums into string and into 4 digit\n // everytime check ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n int generateKey(int n1, int n2, int n3) {\n int i=4;\n string ans=\"\";\n while(i--){\n int a=0,b=0,c=0;\n if(n1){\n a=n1%10;\n n1/=10;\n }\n if(n2){\n b=n2%10;\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string n1=to_string(num1);\n string n2=to_string(num2);\n string n3=to_string(num3);\n \n int s1=n1.size();\n int s2=n2.size();\n int s3=n3.size();\n int n=min(s1,min(s2,...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
1
{ "code": "class Solution {\npublic:\n string preFill(int num) {\n string n = to_string(num);\n if(n.size() == 4) return n;\n while(n.size() != 4) {\n n = \"0\" + n;\n } \n return n;\n }\n\n int generateKey(int num1, int num2, int num3) {\n string n1 = pre...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
2
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string key = \"\";\n for(int i=0;i<4;i++){\n int d = min({num1%10, num2%10,num3%10});\n num1/=10;\n num2/=10;\n num3/=10;\n key = to_string(d) + key;\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
2
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n \n string ans;\n\n while(num1 || num2 || num3){\n\n int rem1 = num1%10;\n int rem2 = num2%10;\n int rem3 = num3%10;\n\n int minDig = min(rem1, min(rem2, rem3));\...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
2
{ "code": "class Solution {\nprivate:\n string padToFourDigits(int n){\n string s=to_string(n);\n while(s.length()<4){\n s=\"0\"+s;\n\n }\n return s;\n }\npublic:\n int generateKey(int num1, int num2, int num3) {\n string s1 = padToFourDigits(num1);\n string s...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
2
{ "code": "class Solution {\npublic:\n string solve(string s) {\n while (s.length() < 4) {\n s = '0' + s;\n }\n return s;\n }\n int generateKey(int num1, int num2, int num3) {\n string s1 = solve(to_string(num1));\n string s2 = solve(to_string(num2));\n st...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
2
{ "code": "class Solution {\npublic:\n string setLength(string s){\n if(s.length() == 4){\n return s;\n }\n while(s.length() < 4){\n s = \"0\" + s;\n }\n return s;\n }\n int min_three(int a, int b, int c){\n int minimum = min(a, b);\n min...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
2
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string n1=to_string(num1),n2=to_string(num2),n3=to_string(num3);\n while(n1.length()!=4)n1=\"0\"+n1;\n while(n2.length()!=4)n2=\"0\"+n2;\n while(n3.length()!=4)n3=\"0\"+n3;\n string temp=\"\"...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
2
{ "code": "#include <algorithm> \nclass Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n int maxi=max(num1, max(num2, num3));\n string m=to_string(maxi);\n int len=m.size();\n int ans=0;\n string s=\"\";\n int n=pow(10,len);\n // int x=10;\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
2
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string a = to_string(num1), b = to_string(num2), c = to_string(num3);\n\n while(a.size() <4) a = '0' + a;\n while(b.size() <4) b = '0' + b;\n while(c.size() <4) c = '0' + c;\n\n string temp =...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
2
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string a = to_string(num1);\n string b = to_string(num2);\n string c = to_string(num3);\n\n while(a.size() < 4){\n string num = a;\n num = '0' + num;\n a = num;\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
2
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n string s1,s2,s3;\n s1=to_string(num1);\n s2=to_string(num2);\n s3=to_string(num3);\n while(s1.size()<4)s1=\"0\"+s1;\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
2
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string s1 = to_string(num1);\n string s2 = to_string(num2);\n string s3 = to_string(num3);\n while (s1.size() < 4) {\n s1 = '0' + s1;\n }\n while (s3.size() < 4) {\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
2
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string s1,s2,s3;\n s1=to_string(num1);\n s2=to_string(num2);\n s3=to_string(num3);\n while(s1.size()<4)s1=\"0\"+s1;\n while(s2.size()<4)s2=\"0\"+s2;\n while(s3.size()<4)s3=\"0\"...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
2
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string str1=\"\",str2=\"\",str3=\"\";\n str1=to_string(num1);\n str2=to_string(num2);\n str3=to_string(num3);\n \n while(str1.size()<4)\n {\n str1='0'+str1;\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
3
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n string s1,s2,s3;\n s1=to_string(num1);\n s2=to_string(num2);\n s3=to_string(num3);\n while(s1.size()<4)s1=\"0\"+s1;\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
3
{ "code": "class Solution {\npublic:\n string convert(int n){\n string ans=to_string(n);\n\n while(ans.size()<4){\n ans.insert(0,1,'0');\n }\n\n return ans;\n }\n\n int generateKey(int num1, int num2, int num3) {\n vector<string> c1;\n string ans;\n\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
3
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string res1 = to_string(num1);\n string res2 = to_string(num2);\n string res3 = to_string(num3);\n\n // Ensure all strings are 4 characters long by adding leading zeros\n while(res1.length() ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
3
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n string one=\"0000\"+to_string(num1);\n string two=\"0000\"+to_string(num2);\n string three=\"0000\"+to_string(num3);\n\n one=one.substr(one.size()-4);\n two=two.substr(two.size()-4);\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "#pragma GCC optimize(\"O3\", \"unroll-loops\")\n\nauto _ = [](){\n return cin.tie(nullptr)->sync_with_stdio(false);\n}();\n\nclass Solution {\npublic:\n string stringHash(const string & s, const int & k) const {\n const int n = s.size();\n\n const auto hash_fn = [](const int & sum){\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "class Solution \n{\npublic:\n string stringHash(const string& s, const int k) \n {\n const size_t LENGTH = s.size();\n string result;\n\n for (size_t i = 0; i <= LENGTH - k; i = i + k)\n {\n int hashValue = 0;\n for (size_t j = i; j < i + k; ++j)\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "class Solution {\npublic:\n string stringHash(string &s, int k) {\n int j=0, ct=0;\n int sum = 0;\n for (int i=0; i<=s.size()-1; i++){\n sum += s[i]-'a';\n if (++ct == k) {\n s[j++] = sum%26 + 'a';\n sum = ct = 0;\n }\n }\n \n s.resize(j); \n return s;\n }\n};", ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "class Solution {\npublic:\n string stringHash(string& s, int k) {\n string ans;\n int i,p=0;\n for(i=0;i<s.size();i++){\n p+=s[i]-'a';\n p%=26;\n if(i%k==k-1){\n ans+=p+'a';\n p=0;\n }\n }\n retu...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "class Solution {\npublic:\n std::string stringHash(std::string const &s, int k) const\n {\n constexpr int alphabetStart = 'a';\n constexpr int alphabetSize = 26;\n const size_t portionSize = k;\n const size_t resultSize = s.size() / k;\n std::string result(resultSiz...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "const char fastio = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\ntypedef long long int ll;\ntypedef pair<int, int> pii;\ntypedef pair<ll, ll> pll;\ntypedef vector<int> vi;\ntypedef vector<ll> vl;\ntypedef vector<pii> vii;\ntypedef vecto...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "#include <iostream>\n#include <string>\n\nclass Solution {\npublic:\n std::string stringHash(const std::string& s, int k) {\n std::string hashs = \"\";\n int n = s.length();\n \n \n if (k <= 0) {\n return \"\";\n }\n\n int c = 0;\n \n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n string result;\n \n for(int i = 0; i < s.size(); i += k) \n {\n int sum = 0;\n for(int j = 0; j < k && i + j < s.size(); j++) \n {\n sum += s[i + j] - 'a';\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n auto ans = string{};\n int const len = s.length();\n\n for (auto i = 0; i < len; i += k) {\n auto hash_val = 0;\n\n for (auto j = 0; j < k; ++j) {\n hash_val += s[i + j] - 'a';\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int lp = s.size() / k; \n string ans = \"\";\n int sum =0;\n int cnt=0;\n for (int i = 0; i < s.size(); i ++) {\n cnt++;\n sum+=s[i]-'a';\n if(cnt%k==0){\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int ascii=int('a');\n int j=0;\n int num=0;\n int n=s.length();\n string ans=\"\";\n for(int i=0;i<n;i++){\n if(j==k){\n num=num%26;\n ans+=char(num+ascii...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n string ans=\"\";\n for(int i=0;i<s.size();i+=k) {\n int sum=0;\n for(int j=0;j<k;j++) {\n sum+=s[i+j]-'a';\n }\n sum=sum%26;\n ans+=(char)(sum+'a');\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n auto hashchar = [](string_view s){return (char)(accumulate(s.begin(), s.end(), 0, [](int a, char b){return a + b - 'a';})%26)+'a';};\n string result;\n for(int start = 0; start < s.size(); start += k) {\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
0
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n string result(s.size()/k, ' ');\n for(int start = 0, idx=0; start < s.size(); start += k, ++idx) {\n result[idx] = accumulate(s.begin()+start, s.begin()+start+k, 0, [](int a, char b){return a + b - 'a';})%26+'a';...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
1
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n=s.length();\n string result=\"\";\n\n for(int i=0;i<n;i+=k){\n\n int sum=0;\n for(int j=i;j<i+k;j++){\n sum +=(s[j]-'a');\n }\n\n int hashed=sum%26;\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
1
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n = s.length();\n int numSubstrings = n / k;\n string result;\n for (int i = 0; i < numSubstrings; i++) {\n int sum = 0;\n for (int j = 0; j < k; j++) {\n sum += s[i * ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n = s.size();\n string ans =\"\";\n int sum =0;\n for(int i=0;i<n;i++){\n sum += (s[i] - 'a');\n if((i+1)%k == 0){\n sum = sum % 26;\n ans += (sum + 'a')...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int value = s.length()/k;\n string store; string result;\n\n int i = 0;\n \n \n while(i < s.length()){\n store.push_back(s[i]);\n \n if((i+1) % k == 0){\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n vector<int> count(26);\n int temp=0;\n string ans=\"\";\n\n for(int i=0;i<s.length();i++){\n count[s[i]-'a']++;\n\n\n if((i+1)%k==0){\n int sum=0;\n for(int...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n string temp=\"\";\n int sum=0;\n string ans=\"\";\n for (char c:s){\n temp+=c;\n sum+=c-97;\n cout<<sum;\n sum%=26;\n if(temp.size()==k)\n { ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n = s.size();string t = \"\";\n vector<int>a(n/k);\n for (int i = 0;i < n/k;i++){\n int m = 0;\n for (int j = i*k;j < (i+1)*k;j++) m+=(s[j]-'a');\n m%=26;\n t+=char(m+'...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n=s.length();\n string s1=\"\";\n string ans=\"\";\n for(int i=0;i<n;i++){\n s1+=s[i];\n if((i+1)%k==0){\n int x=0;\n for(int j=0;j<k;j++){\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n=s.size();\n int z=n/k;\n vector<int>ans;\n int i=0;\n while(z--){\n int num=0;\n int x=k;\n while(x--){\n num+=s[i++]-'a';\n }\n n...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n stringstream ss;\n for(long i=0;i<s.size();i+=k){\n int sum = 0;\n for(int j=0;j<k;j++){\n sum += s[i+j] - 'a';\n }\n sum = sum % 26;\n ss<<(char)(sum + ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n s += ' ';\n int sum;\n const int sub = 'a' * k;\n string res = \"\";\n for (int i = 0; i < s.size(); i++) {\n if (!(i%k)) {\n if (i) {\n sum -= sub;\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int s_length = s.size();\n string res = \"\";\n\n for(int i = 0; i < s_length;i += k){\n string str = \"\";\n int sum = 0;\n for(int j = i; j < i+k && j < s_length; j++){\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int j=0,n=s.length(),c=n/k,sum=0;\n string ans=\"\";\n s+='a';\n for(auto i:s){\n if(j==k){\n \n ans+=(sum)%26 +'a';\n j=0;\n sum=0;\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n = s.size();\n int cnt=0;\n int size = n/k;\n char ans[1005];\n memset(ans, '\\0', sizeof(ans));\n for (int i=0, j=0; i<n; i++) {\n cnt += s[i]-'0'-49;\n if ((i+1)%k ==...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n string result = \"\";\n int n = s.size();\n for(int i=0;i<n;i+=k){\n string sub = s.substr(i,k); \n int sum = 0;\n for(char ch : sub){\n sum += int(ch-'a');\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n void calculateHash(string &result, string sub) {\n int sum = 0;\n for(int i = 0; i < sub.size(); i++) {\n sum += (sub[i] - 'a');\n }\n int index = sum % 26;\n char res = 'a' + index;\n result += res;\n }\n string stri...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n=s.size();\n int div=n/k;\n int i=0;\n string a;\n while(div--){\n string temp=s.substr(i,k);\n int sum=0;\n for(auto ch:temp){\n sum+=ch-'a';\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int l=s.size()/k;\n string re=\"\";\n for(int i=0;i<=s.size()-k;i+=k){\n string p=s.substr(i,k);\n int k=0;\n for(auto x:p){\n k+=x-'a';\n }\n k%=...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "#include <string>\nclass Solution {\npublic:\n string stringHash(string s, int k) {\n \n string resul=\"\";\n for(int i=0; i<s.size(); i+=k){\n string sb= s.substr(i,k);\n \n int val=0;\n for(char i :sb){\n val= val +(i-'a');\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n=s.size();\n if(k==1) return s;\n string ans=\"\";\n for(int i=0;i<n;i+=k){\n string t=s.substr(i,k);\n int sum=0;\n for(int j=0;j<t.size();j++){\n sum+=t[j...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
2
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n\n string str;\n\n char arr[26];\n for(int i=0; i<26; i++) {\n arr[i] = 'a'+i; \n }\n\n int j=0;\n for(int i=0; i<s.length(); i++){\n string a = s.substr(j,k);\n j+=k;\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) \n {\n string str;\n int n=s.size();\n for(int i=0;i<n;i+=k)\n { \n int sum=0;\n string sub=s.substr(i,k);\n for(auto x:sub)\n sum+=x-'a';\n sum%=26;...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n\n string str;\n\n char arr[26];\n for(int i=0; i<26; i++) {\n arr[i] = 'a'+i; \n }\n\n int j=0;\n for(int i=0; i<s.length(); i++){\n string a = s.substr(j,k);\n j+=k;\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n\n string str;\n\n char arr[26];\n for(int i=0; i<26; i++) {\n arr[i] = 'a'+i; \n }\n\n int j=0;\n for(int i=0; i<s.length(); i++){\n string a = s.substr(j,k);\n j+=k;\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n = s.size();\n vector<int> pref(n+1,0);\n for(int i=1; i<=n; i++){\n pref[i]=(pref[i-1]%26+(s[i-1]-'a')%26)%26;\n }\n string ans = \"\";\n for(int i=k; i<=n; i+=k) ans+=(char)((pref[i]%26-p...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n vector<int> pref(s.size()+1);\n for (int i = 0; i < s.size(); ++i) {\n pref[i+1] = s[i]-'a';\n }\n for (int i = 0; i < s.size(); ++i) {\n pref[i+1]+=pref[i];\n }\n string an...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n string ans;\n int n=s.length();\n int i=0;\n\n while(i<n){\n string word=\"\";\n int sum=0;\n while(word.length()!=k){\n word+=s[i];\n sum+=s[i]-'a';\...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\nstring hash(string sub)\n{\n int sum=0;\n for(auto i:sub)\n {\n int temp=i-'a';\n sum+=temp;\n }\n int rem=sum%26;\n string ch= \"\";\n ch+=(char)(rem+'a');\n return ch;\n}\n string stringHash(string s, int k) {\n int n=s.size();\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n int fun(string s){\n int ans=0;\n for(int i=0;i<s.size();i++){\n ans+=s[i]-'a';\n }\n ans=ans%26;\n return ans;\n }\n string stringHash(string s, int k) {\n string res=\"\";\n for(int i=0;i<s.size();){\n string a=\"\";\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n=s.length();\n vector<string> v(n/k, \"\");\n for(int a=0;a<n;a+=k){\n string t = \"\";\n int ans=0;\n for(int b=a;b<a+k;b++){\n ans+= (s[b]-'a');\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n std::string ans;\n int n = s.length(), l = 0;\n int lengthResult = n / k;\n std::vector<std::string> vecString(lengthResult);\n for(int i = 0; i < lengthResult; ++i)\n {\n vecString[i] = s.s...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int tot=0;\n string t=\"\";\n int l=0, r=s.length();\n while(l<r){\n s+='a' + (resChar(s.substr(l, k)));\n l+=k;\n }\n return s.substr(r);\n }\n int resChar(string t){...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n if(k==1)\n return s;\n string ans=\"\";\n int len=s.length();\n for(int i=0; i<len; i+=k) {\n string temp=s.substr(i, k);\n int x=0;\n for(int j=0; j<k; j++) {\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n\nchar get_character(string str)\n{\n int sum = 0;\n for(int i = 0; i < str.length(); i++)\n {\n sum += str[i] - 'a';\n }\n return sum%26 + 'a';\n}\n\n string stringHash(string s, int k) {\n string result = \"\";\n\n int left = 0;\n i...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n\nchar get_character(string str)\n{\n int sum = 0;\n for(int i = 0; i < str.length(); i++)\n {\n sum += str[i] - 'a';\n }\n return sum%26 + 'a';\n}\n\n string stringHash(string s, int k) {\n string result = \"\";\n\n int left = 0;\n i...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string stringHash(string s, int k) {\n\n int n = s.size();\n\n int sum=0;\n string result;\n char ch;\n int i=0;\n \n\n while(i<n)\n {\n int j = 0;\n sum =...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n unordered_map<char,int> h;\n int i=0;\n for(char c = 'a'; c<='z'; c++){\n h[c]=i;\n i++;\n }\n string ans = \"\";\n for(int i=0; i<s.size(); i+=k){\n int sum =0;\...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n string res=\"\";\n int n=s.size();\n int count=0;\n int csum=0;\n for(int i=0;i<n;i++){\n count++;\n csum+=s[i]-'a';\n\n if(count==k){\n res=res+ char('a'...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n unordered_map<char,int> h;\n int i=0;\n for(char c = 'a'; c<='z'; c++){\n h[c]=i;\n i++;\n }\n string ans = \"\";\n for(int i=0; i<s.size(); i+=k){\n int sum =0;\...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n=s.size();\n int part=n/k;\n int i=0;\n string result=\"\";\n string temp=\"\";\n int sum=0;\n while(i<n){\n int num=s[i]-'a';\n // cout<<num<<endl;\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n vector<string> v;\n string temp=\"\";\n for(int i=0;i<s.size();i++){\n temp+=s[i];\n if(temp.size()==k){\n v.push_back(temp);\n temp=\"\";\n }\n }...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n=s.length();\n vector<string>v;\n string temp;\n int count=0;\n string res=\"\";\n for(int i=0;i<n;i++)\n {\n temp+=s[i];\n count++;\n if(count==k)\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n unordered_map<char, int> hash;\n for(char ch = 'a'; ch <= 'z'; ch++)\n hash[ch] = ch - 'a';\n \n string result = \"\";\n for(int i = 0; i < s.size(); i += k){\n string temp = s.sub...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n // unordered_map<char, int> hashVal={\n // {'a', 0},\n // {'b', 1},\n // {'c', 2},\n // {'d', 3},\n // {'e', 4},\n // {'f', 5},\n // {'g', 6},\n /...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n vector<string>v;\n int n=s.size();\n for(int i=0;i<n;i+=k){\n v.push_back(s.substr(i,min(k,n-i)));\n }\n string ans=\"\";\n for(int i=0;i<v.size();i++){\n string l=v[i];\n ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n vector<int>hash(26,0);\n int n = s.length();\n for(int i=0; i<26; i++)\n {\n hash[i] = i;\n }\n\n int i = 0;\n vector<int>v;\n while(i<n)\n {\n int j = ...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n int makeToNumber(string s)\n {\n int value = 0;\n for(int i=0;i<s.size();i++)\n {\n value += s[i] - 'a';\n }\n \n value %= 26;\n \n return value;\n }\n \n char makeToChar(int n)\n {\n cha...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n=s.size();\n vector<string> h;\n string t;\n for(int i=1;i<=n;i++){\n t+=s[i-1];\n if(i%k==0){\n h.push_back(t);\n t.clear();\n }\n }\...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n int n=s.size();\n vector<string> h;\n string t;\n for(int i=1;i<=n;i++){\n t+=s[i-1];\n if(i%k==0){\n h.push_back(t);\n t.clear();\n }\n }\...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string stringHash(string s, int k) {\n vector<string> str ;\n\n for(int i = 0 ;i<s.size() ;++i){\n str.push_back(s.substr(i,k)) ;\n i+=k-1;\n }\n\n string res=\"\" ;\n\n vector<int> eq(str.size()) ;\n int i = 0 ;...
3,540
<p>You are given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, where <code>n</code> is a <strong>multiple</strong> of <code>k</code>. Your task is to hash the string <code>s</code> into a new string called <code>result</code>, which has a length of <code>n / k</code>.</p> <p>First, di...
3
{ "code": "class Solution {\npublic:\n string a=\"abcdefghijklmnopqrstuvwxyz\";\n unordered_map<char , int>mp;\n char kjitna(string &mera){\n int news=0;\n for(auto x:mera){\n news+=mp[x];\n }\n news=news%26;\n return a[news];\n }\n st...