id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "inline unsigned long long vecfromstr(std::string& s, std::vector<unsigned long long>& chalk) {\n unsigned long long number = 0;\n unsigned long long prev_number = 0;\n chalk.clear();\n for (char* c = &s[1]; *c != '\\0'; c++) {\n if (*c >= 48 && *c <= 57) {\n number = number * ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "inline unsigned long long vecfromstr(std::string& s, std::vector<unsigned long long>& chalk) {\n unsigned long long number = 0;\n unsigned long long prev_number = 0;\n chalk.clear();\n for (char* c = &s[1]; *c != '\\0'; c++) {\n if (*c >= 48 && *c <= 57) {\n number = number * ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "inline unsigned long long vecfromstr(std::string& s, std::vector<unsigned long long>& chalk) {\n unsigned long long number = 0;\n unsigned long long prev_number = 0;\n chalk.clear();\n for (char* c = &s[1]; *c != '\\0'; c++) {\n if (*c >= 48 && *c <= 57) {\n number = number * ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "inline unsigned long long vecfromstr(std::string& s, std::vector<unsigned long long>& chalk) {\n unsigned long long number = 0;\n unsigned long long prev_number = 0;\n chalk.clear();\n for (char* c = &s[1]; *c != '\\0'; c++) {\n if (*c >= 48 && *c <= 57) {\n number = number * ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "inline unsigned long long vecfromstr(std::string& s, std::vector<unsigned long long>& chalk) {\n unsigned long long number = 0;\n unsigned long long prev_number = 0;\n chalk.clear();\n for (char* c = &s[1]; *c != '\\0'; c++) {\n if (*c >= 48 && *c <= 57) {\n number = number * ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for (string str, k_str; getline(cin, str) && getline(cin, k_str);) {\n istring...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for (string str, k_str; getline(cin, str) && getline(cin, k_str);) {\n istring...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for (string str, k_str; getline(cin, str) && getline(cin, k_str);) {\n istring...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for (string str, k_str; getline(cin, str) && getline(cin, k_str);) {\n istring...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += chalk[i];\n if (sum > k) {\n break;\n }\n }\n\n k = k % sum;\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n long long sum = 0;\n for (int i = 0; i < n; i++) {\n sum += chalk[i];\n }\n long long rem = k;\n rem = rem % sum;\n for (int i = 0; i < n; i++)...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n bool check=true; int m{0};\n for (int a: chalk) {\n if (m+a<=k) {\n m+=a;\n } else {\n check=false; break;\n }\n }\n if (check) k=k%m;\n...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n long s = 0, q, result;\n for(long i = 0; i < chalk.size(); i++){\n s += chalk[i];\n }\n q = k / s;\n long remChalk = k - q * s;\n for(long i = 0; i < chalk.size(); i++){\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n long long sum = 0;\n for(auto &it: chalk) {\n sum += it;\n }\n\n int rem = k % sum;\n\n for(int i=0; i<chalk.size(); i++) {\n if(chalk[i] > rem) {\n return...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int s=0;\n for(int i=0;i<chalk.size();i++){\n if(s+chalk[i]>k)return i;\n else\n s+=chalk[i];\n }\n k=k%s;\n for(int i=0;i<chalk.size();i++){\n if(k...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n // Find the sum of all elements.\n int sum = 0;\n for (int i = 0; i < chalk.size(); i++) {\n sum += chalk[i];\n if (sum > k) {\n break;\n }\n }\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n long long total = accumulate(begin(chalk),end(chalk),0LL);\n k %= total;\n for(int i=0;i<chalk.size();i++){\n if(chalk[i]>k){\n return i;\n }else{\n k-=ch...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
0
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n\n long long int sum{}; \n int ans{};\n\n for(int i{}; i < chalk.size(); i++)\n {\n sum += chalk.at(i);\n }\n\n k = k % sum;\n\n for(int i{}; i < chalk.size(); i++)\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
1
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n long long sum=0;\n for(int i=0;i<chalk.size();i++)\n {\n sum+=chalk[i];\n }\n k=k%sum;\n int i=0;\n while(chalk[i]<=k)\n {\n k-=chalk[i];\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
1
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, long long k) {\n long long sum = 0;\n\n for (auto it = chalk.begin(); it != chalk.end(); it++) {\n sum += *it;\n }\n\n k %= sum;\n\n for (int i = 0; i < chalk.size(); i++) {\n k -= ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n long long totalchalks = 0;\n for (int ch : chalk)\n totalchalks += ch;\n\n k = k % totalchalks;\n for (int i = 0; i < chalk.size(); i++) {\n if (k < chalk[i])\n r...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n long long sum = 0;\n int n = chalk.size();\n for(int i =0 ;i<n;i++){\n sum = sum+chalk[i];\n }\n if(k>=sum){\n int rem = k%sum;\n int pref = 0;\n int ind = 0;\n while(rem>0){\n...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk,int initialChalkPieces){\n long long totalChalkNeeded = 0;\n for(int studentChalkUse : chalk){\n totalChalkNeeded += studentChalkUse;\n }\n int remainingChalk = initialChalkPieces % totalChalkNeeded;\...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int a[100001] = {0};\n for( int i=0; i<chalk.size(); i++ ){\n if( chalk[i] > k ){\n return i;\n }\n else if( i==0 ) a[i] = chalk[i];\n else a[i] = a[i-1] ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n int prefix[n];\n if(chalk[0]>k) return 0;\n prefix[0]=chalk[0];\n for(int i = 1;i<n;i++){\n prefix[i] = prefix[i-1] +chalk[i];\n if( prefix[i]>k)...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n long long pre[n]; pre[0] = chalk[0];\n for (int i = 1; i < n; i++) pre[i] = pre[i - 1] + chalk[i];\n k %= pre[n - 1];\n return upper_bound(pre, pre + n, k) - pre;\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\nint n ;\n int ceil(long prefixSum[] , int remain){\n int start = 0;\n int end = n-1;\n int ans = -1;\n \n\n while(start <= end){\n int mid = start + (end - start) /2;\n\n if(prefixSum[mid] == remain ){\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n long long pref[chalk.size()];\n memset(pref, 0, sizeof(pref));\n pref[0] = chalk[0];\n for(int i=1; i < chalk.size(); ++i){\n pref[i] = pref[i-1]+chalk[i];\n }\n k %= pref[ch...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n long sums[n];\n sums[0] = chalk[0];\n for (int i = 1; i < n; ++i) {\n sums[i] = sums[i - 1] + chalk[i];\n }\n k %= sums[n - 1];\n int l = 0;\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "const int N = 1e5 + 10;\nclass Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n long long sum = 0;\n int n = chalk.size();\n for(int i = 0; i < n; ++i){\n sum += chalk[i];\n }\n\n int m = k % sum;\n \n long long pf[N] = {...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& arr, int k) {\n int n = arr.size();\n long long sum = 0;\n long long pre[n];\n memset(pre,0,sizeof pre);\n \n for(int i=0; i<n; ++i) {\n sum += (long long)arr[i];\n if(i == 0) {\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n vector<int>v={1,2,3,5};\n vector<int>v1={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int ind=0;\n int n=chalk.size();\n unordered_map<int,int>mp;\n \n for(int i=0;i<n;i++){\n mp[chalk[i]]++;\n if(mp.size()>1)break;\n }\n if(mp.size()==1){\...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n vector<int> psum;\n long long sum = 0;\n for(int i = 0; i<n; i++){\n sum+=chalk[i];\n }\n k = k%sum;\n psum.push_back(0);\n int i = 0;\n...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n long long sum = 0;\n int n = chalk.size();\n for(int i =0 ;i<chalk.size();i++)\n {\n sum+= chalk[i];\n if(sum > k)\n {\n return i;\n }\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\nint chalkReplacer(std::vector<int>& chalk, int k) {\n std::vector<int> prefix_sum;\n prefix_sum.reserve(chalk.size());\n int prev = 0;\n for (int i = 0; i < chalk.size(); ++i) {\n if (k < (prev = prefix_sum.emplace_back(prev + chalk[i]))) {\n return i;\n }\n }\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n const int n = chalk.size();\n vector<int> prefixSum;\n prefixSum.reserve(n);\n prefixSum.emplace_back(chalk[0]);\n for (int index = 1; index < n; ++index) {\n prefixSum.emplace_back...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "// DATA_____________________________________________________________________________________________________\n// vector<int> chalk ----> amount that ith student uses to solve a problem \n// int k\n// _________________________________________________________________________________________________________\n...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int s = chalk.size(), *sums = new int[s], currSum{};\n for (int i{}; i < s; ++i) {\n currSum += chalk[i];\n if (currSum > 1e9) {\n s = i;\n break;\n }...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution{\npublic:\n static int chalkReplacer(vector<int>& chalk, int k){\n static vector<long long> s;\n s.resize(chalk.size()+1);\n s[0]=0;\n for(int i=0;i<chalk.size();++i){\n s[i+1]=s[i]+chalk[i];\n }\n k%=s.back();\n auto it=upper_bo...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int s = chalk.size(), *sums = new int[s], currSum{};\n for (int i{}; i < s; ++i) {\n currSum += chalk[i];\n if (currSum > 1e9) {\n s = i;\n break;\n }...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int s = chalk.size(), *sums = new int[s], currSum{};\n for (int i{}; i < s; ++i) {\n currSum += chalk[i];\n if (currSum > 1e9) {\n // if (currSum > k) return i - 1;\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int binarySearch(long long int* chalk, int k, int n)\n {\n //找到第一個大於K的\n int l = 0;\n int r = n-1;\n\n while(l < r)\n {\n int mid = l+(r-l)/2;\n if(chalk[mid] > k)\n {\n r = mid;\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int sum=0;\n vector<int> prefix;\n for(int i=0; i<chalk.size(); ++i){\n sum+=chalk[i];\n prefix.push_back(sum);\n if(sum>k) return i;\n }\n k%=sum;\n re...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n=chalk.size();\n\n vector<int> prefixSum;\n int sum=0;\n for(int i=0; i<n; i++){\n sum+=chalk[i];\n if(sum>k){\n return i;\n }\n prefix...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n vector<int>a;\n int n = chalk.size();\n long long int sum = 0;\n for(int i:chalk){\n if(sum>k) \n break;\n sum+=i;\n }\n if(sum<k)\n k = ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n\n /* Our predicate function */\n bool predicate_func(int k, vector<int> &chalk, vector<int> &psum, int idx)\n {\n //printf(\"idx=%d\\n\",idx);\n int left;\n if (idx != 0)\n left = k - psum[idx-1];\n else\n left = k;\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n \n long long total=0;\n int i=0,n=chalk.size();\n vector<int>sum;\n while(i<n){\n if(k<chalk[i]){\n return i;\n }\n total+=chalk[i];\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n vector<int> v;\n int sum=0;\n for(int i=0;i<chalk.size();i++){\n v.push_back(sum);\n sum+=chalk[i];\n if(sum>k) return i;\n }\n k=k%sum;\n int it=upper_...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int running = 0;\n vector<int> totals = {};\n\n for (auto it = chalk.begin(); it < chalk.end(); ++it){\n running += *it;\n if (running > k){\n return it - chalk.begin();...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n \n return by_queue(chalk, k);\n //return by_binary_search(chalk, k);\n }\nprivate:\n int by_binary_search(vector<int>& chalk, int k) {\n return 1;\n }\n int by_queue(vector<int>& chalk, i...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\nint solve(vector<int>& chalk, int &k,int index){\n if(k==0||k<chalk[index])\n return index;\n int sum=k-chalk[index];\n index=(index+1)%chalk.size();\n return solve(chalk,sum,index);\n\n}\n\n int chalkReplacer(vector<int>& chalk, int k) {\n long long sum=0;\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\nint solve(vector<int>& chalk, int &k,int index){\n if(k==0||k<chalk[index])\n return index;\n int sum=k-chalk[index];\n index=(index+1)%chalk.size();\n return solve(chalk,sum,index);\n\n}\n\n int chalkReplacer(vector<int>& chalk, int k) {\n long long sum=0;\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n\n //linear scan/brute force too slow\n int AltSubProblem(vector<int> student, int k) {\n int index = 0;\n int size = student.size();\n while (k > 0 && student[index] <= k) {\n k -= student[index];\n index = (index + 1) % size;\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n\n //linear scan/brute force too slow\n int AltSubProblem(vector<int> student, int k) {\n int index = 0;\n int size = student.size();\n while (k > 0 && student[index] <= k) {\n k -= student[index];\n index = (index + 1) % size;\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\nint solve(vector<int>& chalk, int &k,int index){\n if(k==0||k<chalk[index])\n return index;\n int sum=k-chalk[index];\n index++;\n return solve(chalk,sum,index);\n\n}\n\n int chalkReplacer(vector<int>& chalk, int k) {\n long long sum=0;\n for(int i=0;i<cha...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n\n //linear scan/brute force too slow\n int AltSubProblem(vector<int> student, int k) {\n int index = 0;\n int size = student.size();\n while (k > 0 && student[index] <= k) {\n k -= student[index];\n index = (index + 1) % size;\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n long long sum = accumulate(chalk.begin(),chalk.end(),0LL);\n // cout<<sum;\n int rem = k%sum;\n if(rem == 0) return 0;\n vector<int> presum(n);\n presum[0...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n long long sum = accumulate(chalk.begin(),chalk.end(),0LL);\n // cout<<sum;\n int rem = k%sum;\n if(rem == 0) return 0;\n vector<int> presum(n);\n presum[0...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n long long sum = accumulate(chalk.begin(),chalk.end(),0LL);\n // cout<<sum;\n int rem = k%sum;\n if(rem == 0) return 0;\n vector<int> presum(n);\n presum[0...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n long long findSum(vector<int> vec) {\n long long sum = 0;\n\n for (auto num: vec) sum += num;\n\n return sum;\n }\n\n int chalkReplacer(vector<int>& chalk, int k) {\n long long sum = findSum(chalk);\n int newChalk = k % sum;\n i...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n vector<int> pref(chalk.size(), 0);\n pref[0] = chalk[0];\n if(pref[0] > k) return 0;\n for(int i = 1; i < chalk.size(); i++) {\n pref[i] = pref[i - 1] + chalk[i];\n if(pref[i] >...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int size=chalk.size();\n int pointer=0;\n int ans=-1;\n long long sum=0;\n vector<int> prefixSum(size);\n\n for(int i=0;i<size;i++){\n sum+=chalk[i];\n prefixSum[i...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n=chalk.size();\n if(chalk[0]>k) return 0;\n vector<int> presum(n,0);\n presum[0]=chalk[0];\n for(int i=1;i<n;i++){\n presum[i]=presum[i-1]+chalk[i];\n if(presum[i]>...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n vector<int> preSum = chalk;\n int sum = 0;\n\n for (int i = 0; i < chalk.size(); i++) {\n if (sum > k - chalk[i]) return i;\n\n sum += chalk[i];\n }\n\n k = k % sum;\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>chalk, int k) {\n int n = chalk.size();\n long long totalChalk = 0;\n \n for (int i=0;i<n;i++) {\n totalChalk += chalk[i];\n }\n \n k %= totalChalk;\n \n for (int i=0;i<n;i+...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n long long sum(vector<int>arr){\n long long sum=0,n=arr.size();\n for(int i=0;i<n;i++){\n sum+=arr[i];}\n return sum;\n }\n int chalkReplacer(vector<int>& chalk, int k) {\n int n=chalk.size();\n if(n==1) return 0;\n lo...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n deque<int> dq;\n\n for (int i = 0; i < chalk.size(); i++) {\n dq.push_back(i);\n }\n\n long long totalChalk = 0;\n for (int amount : chalk) {\n totalChalk += amount;\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n queue<int> q;\n long sum = 0;\n for(int i = 0 ;i < n ; i++){\n sum += chalk[i];\n q.push(chalk[i]);\n }\n k = k % sum;\n \n f...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n long sum = 0;\n vector<long> s;\n int i = 0;\n int j = 0;\n while(k >= 0 && i < n){\n j = i;\n sum += chalk[i];\n s.push_back(su...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n long sum = 0;\n vector<long> s;\n int i = 0;\n int j = 0;\n while(k >= 0 && i < n){\n j = i;\n sum += chalk[i];\n s.push_back(su...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n long sum = 0;\n vector<long> s;\n int i = 0;\n int j = 0;\n while(k >= 0 && i < n){\n j = i;\n sum += chalk[i];\n s.push_back(su...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n long sum = 0;\n vector<long> s;\n int i = 0;\n int j = 0;\n while(k >= 0 && i < n){\n j = i;\n sum += chalk[i];\n s.push_back(su...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n long sum = 0;\n vector<long> s;\n int i = 0;\n int j = 0;\n while(k >= 0 && i < n){\n j = i;\n sum += chalk[i];\n s.push_back(su...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n vector<long long> preSum;\n int n = chalk.size();\n for(int i=0; i<n; i++){\n if(i==0){\n preSum.push_back(chalk[i]);\n }\n else{\n preSum.push...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n queue<int> q;\n int n = chalk.size();\n long long int sum{};\n for(auto x:chalk){\n q.push(x);\n sum += x;\n }\n k = k%sum;\n int i{};\n while(q.fron...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n queue<int>q;\n int n = chalk.size();\n long long sum=0;\n for(int i=0;i<n;i++)\n {\n q.push(i);\n sum+=chalk[i];\n \n }\n k = k%sum;\n while(chal...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n queue<int> q;\n int n = chalk.size();\n long long total = 0;\n total = accumulate(chalk.begin(), chalk.end(), total);\n \n while(k>=total){\n k -= total;\n }\n\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n queue<int> q;\n long sum = 0;\n for(int i = 0 ;i < n ; i++){\n sum += chalk[i];\n q.push(chalk[i]);\n }\n k = k % sum;\n int itr = 0...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "int findId(int k, vector<long long> ps, int n){\n int l = 0;\n int r = n-1;\n int mid = l+((r-l)>>1);\n while(l<r){\n if(ps[mid]<=k){\n l = mid+1;\n }\n else{\n r = mid;\n }\n mid = l+((r-l)>>1);\n }\n return r;\n\n}\nclass Solution...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n queue<int> q;\n long long int sum=0;\n int n=chalk.size();\n if(n==1) return 0;\n for(auto x: chalk){\n q.push(x);\n sum+=x;\n }\n while(k>sum){\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n queue<int> q;\n long long int sum=0;\n int n=chalk.size();\n if(n==1) return 0;\n for(auto x: chalk){\n q.push(x);\n sum+=x;\n }\n while(k>sum){\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n queue<int> q;\n long long int sum=0;\n int n=chalk.size();\n if(n==1) return 0;\n for(auto x: chalk){\n q.push(x);\n sum+=x;\n }\n while(k>sum){\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n queue<int> q;\n long long int sum=0;\n int n=chalk.size();\n if(n==1) return 0;\n for(auto x: chalk){\n q.push(x);\n sum+=x;\n }\n while(k>sum){\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int kk) {\n queue<int>q; long long sum=0; long long k=kk;\n for(int i=0;i<chalk.size();i++){\n q.push(i);\n sum=sum+chalk[i];\n }\n while(k-sum>0){\n k=k-sum;\n }\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n #define ll long long\n int chalkReplacer(vector<int>& arr, int k) {\n ll n = arr.size();\n ll sum = 0;\n for(auto it: arr) sum+=it; \n if(k%sum == 0) return 0;\n\n sum = (ll)k%sum;\n \n vector<ll> pre(n,0);\n pre[0] =...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n\n long long total = accumulate(chalk.begin(),chalk.end(),0LL);\n\n if(k>=total)\n k=k%total;\n if(k==0)\n return 0;\n\n vector<long long> prefix(chalk.size(),0);\n\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& c, int k) {\n long long int ts = 0; \n for (int cn : c) {\n ts += cn;\n }\n\n k %= ts;\n\n if (k == 0) {\n return 0; \n }\n \n vector<long long> cs(c.size(), 0);\n cs[0] = c[0];\n for (int i = 1; i <...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n long long sum = 0; \n for(int i = 0; i < n; i++){\n sum += chalk[i];\n }\n int rem = k % sum;\n if(rem == 0){\n return 0;\n }\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n // cout<<\"yed\";\n long long sum = 0; \n for(auto i: chalk){\n sum += i;\n }\n // cout<<\"yed\";\n // cout<<sum<<endl;\n k = (k - (k/sum)*sum);\n if(k == 0){...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\n \npublic: \n int binarySearch(vector<long long> &vec, long long key) {\n int left = 0, right = vec.size() - 1;\n int result = -1; // or any other invalid value\n\n while (left <= right) {\n int mid = left + (right - left) / 2;\n\n if (vec[mid] <= key) {\n...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution \n{\npublic:\n int chalkReplacer(vector<int>& chalk, int k) \n {\n int n = chalk.size();\n vector<long long> prefixSum(n);\n prefixSum[0] = chalk[0];\n for(int i = 1; i < n; ++i) \n prefixSum[i] = prefixSum[i - 1] + chalk[i];\n k = k % pref...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n=chalk.size();\n vector<long long>prefix(n);\n prefix[0]=chalk[0];\n for(int i=1;i<n;i++) prefix[i]=prefix[i-1]+chalk[i];\n long long rem=k%prefix.back();\n for(int i=0;i<n;i++) if...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& c, int k) {\n long n = c.size(), sum, left;\n vector<long> pref(n); // creating new prefix sum vector due to overflow else not requried \n pref[0] = c[0];\n for(int i = 1;i<n;i++) pref[i] = pref[i-1] + c[i];\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n // int binary_search(const vector<uint64_t>& chalk, int left, int len, int k) {\n // if ((len >> 1) == 0)\n // return (chalk[left] > k) ? left : left + 1;\n // int mid = len / 2;\n // auto test = chalk[left + mid];\n // if (test == k)\n ...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n=chalk.size();\n vector<long> prefixSum(n);\n prefixSum[0]=chalk[0];\n for (int i=1;i<n;i++) prefixSum[i]=chalk[i]+prefixSum[i-1];\n k%=prefixSum[n-1];\n return binarySearch(prefix...
2,006
<p>There are <code>n</code> students in a class numbered from <code>0</code> to <code>n - 1</code>. The teacher will give each student a problem starting with the student number <code>0</code>, then the student number <code>1</code>, and so on until the teacher reaches the student number <code>n - 1</code>. After that,...
3
{ "code": "class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n \n vector<long long int> pref(chalk.size());\n pref[0] = chalk[0];\n for(int i = 1; i < chalk.size(); i++) {\n \n pref[i] = pref[i-1] + chalk[i];\n }\n \n ...
2,025
<p>You are given an array of strings <code>words</code> (<strong>0-indexed</strong>).</p> <p>In one operation, pick two <strong>distinct</strong> indices <code>i</code> and <code>j</code>, where <code>words[i]</code> is a non-empty string, and move <strong>any</strong> character from <code>words[i]</code> to <strong>a...
0
{ "code": "class Solution {\npublic:\n bool makeEqual(vector<string>& words) {\n int hash_table[26] = {0};\n\n for(const string &word : words){\n for(const char &c : word){\n hash_table[c-'a']++;\n }\n }\n int n = words.size();\n for(int i = 0...
2,025
<p>You are given an array of strings <code>words</code> (<strong>0-indexed</strong>).</p> <p>In one operation, pick two <strong>distinct</strong> indices <code>i</code> and <code>j</code>, where <code>words[i]</code> is a non-empty string, and move <strong>any</strong> character from <code>words[i]</code> to <strong>a...
0
{ "code": "class Solution {\npublic:\n bool makeEqual(vector<string>& words) {\n bool moreThanOne = false;\n if(words.size() == 1)\n return true;\n vector<int> letters(26, 0);\n for(int i = 0; i<words.size(); i++){\n for(int j = 0; j<words[i].length(); j++){\n ...
2,025
<p>You are given an array of strings <code>words</code> (<strong>0-indexed</strong>).</p> <p>In one operation, pick two <strong>distinct</strong> indices <code>i</code> and <code>j</code>, where <code>words[i]</code> is a non-empty string, and move <strong>any</strong> character from <code>words[i]</code> to <strong>a...
0
{ "code": "class Solution {\npublic:\n // Function to check if the characters in the words can be rearranged\n // to make each word have the same characters in the same frequency.\n bool makeEqual(vector<string>& words) {\n\n // Array to store the count of each character (initialized to 0).\n v...