id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int mod = 1e9+7;\n long long dp[100006];\n long long solve(int len, int zero, int one, int low , int high){\n if(len > high) return 0;\n if(dp[len] != -1) return dp[len];\n\n if(len >= low){\n return dp[len] = (1 + solve(len+zero,zero,one...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n\n int mod = 1e9+7;\n int dp[200001];\n \n int solve(int len,int z,int o,int l,int h){\n if(len>h) return 0;\n if(dp[len]!=-1) return dp[len];\n int temp = (solve(len+z,z,o,l,h)%mod + solve(len+o,z,o,l,h)%mod)%mod;\n if(len<l) return dp[len...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n vector<int> dp;\n int mod = 1e9+7;\n int countGoodStrings(int low, int high, int zero, int one) {\n dp.resize(high+1,-1);\n int res = 0;\n for(int i = low;i<=high;i++){\n res = (res + dfs(i,zero,one))%mod;\n }\n return res;\...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int mod = 1e9+7;\n int helper(int idx, int zero, int one, vector<int> &dp)\n {\n\t\t//base case\n if(idx == 0)\n {\n return 1;\n }\n if(idx < 0)\n {\n return 0;\n }\n if(dp[idx] != -1)\n {\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n vector<int> dp;\n int mod = 1e9+7;\n int countGoodStrings(int low, int high, int zero, int one) {\n int res = 0;\n dp.resize(high+1,-1);\n for(int i = low;i<=high;i++){\n res = (res + dfs(i,zero,one))%mod;\n }\n return res;\...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int l,h,ze,on;\n const int mod=1e9+7;\n int solve(int n,vector<int>&dp){\n if(n>h) return 0;\n if(dp[n]!=-1) return dp[n];\n int count0=0,count1=0;\n if(n>=l) count0=1+solve(n+ze,dp);\n else count0=solve(n+ze,dp);\n count1=s...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\nprivate:\n const int mod = 1e9 + 7;\npublic:\n int solve(int n, int zero, int one, vector<int>& dp){\n if(n == 0){\n return 1;\n }\n if(dp[n] != -1){\n return dp[n];\n }\n int ans = 0;\n if(n - zero >= 0){\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int t[100002];\n int solve(int low,int high,int zero, int one,int curr_length){\n \n if(curr_length>high)\n return 0;\n if(t[curr_length]!=-1)\n return t[curr_length];\n int total=0;\n if(curr_length>=lo...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n typedef long long ll;\n int M = 1e9+7;\n int t[100001];\n int solve(int len, int low, int high, int zero, int one){\n if(len > high) return 0; //don't check for further strings\n if(t[len]!=-1) return t[len];\n ll possibility = 0;\n if(len...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "class Solution {\npublic:\n int dp[100001];\n int MOD = 1e9 +7;\n int helper(int len, int low, int high, int zero, int one) {\n if (len > high)\n return 0;\n if (dp[len] != -1)\n return dp[len];\n\n bool isCorrect = false;\n if (len >= low && len <...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
1
{ "code": "long long dp[100005];\nconst int MOD = 1e9 + 7;\nclass Solution {\npublic:\n long long helper(int low, int high, int zero, int one, int len){\n if(len > high)return 0;\n if(dp[len] != -1)return dp[len];\n long long ans = 0;\n if(len >= low)ans++;\n ans += helper(low, h...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\n int dp[200001];\n int m=1e9+7;\n int f(int len,int low, int high, int zero, int one)\n {\n if(len>high)\n return dp[len]=0;\n if(dp[len]!=-1)\n return dp[len];\n int add=0;\n if(len>=low)\n {\n add=1;\n }\n\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n int L,H,Z,O;\n int mod=1e9+7;\n int t[1000001];\n int swap(int l)\n {\n if(l>H)\n {\n return 0;\n }\n bool onee=false;\n if(l>=L && l<=H)\n {\n onee=true;\n }\n if(t[l]!=-1)\n {\n...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n int l,h,ze,on;\n const int mod=1e9+7;\n int solve(int n,vector<int>&dp){\n if(n>h) return 0;\n if(dp[n]!=-1) return dp[n];\n int countValid=(n>=l && n<=h)?1:0;\n int count0=solve(n+ze,dp);\n int count1=solve(n+on,dp); \n retu...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n const int MOD = 1e9+7;\n int Z,O,L,H;\n int solve(int l,vector<int> &t)\n {\n if(l>H)\n {\n return 0;\n }\n if(t[l]!=-1) return t[l];\n bool addOne=false;\n if(l>=L && l<=H)\n {\n addOne = true;\n...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\nint L,H,Z,O;\nint solve(int l,vector<int>&dp){\n if(l>H) return 0;\n if(dp[l]!=-1) return dp[l];\n int count=0;\n if(l>=L){\n count=1;\n }\n int a0=solve(l+Z,dp);\n int a1=solve(l+O,dp);\n return dp[l]= (a0+a1+count)%1000000007;\n\n}\n\n int countGoodStrings(int low, ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n int dp[100001],MOD=1e9+7;\n int f(int l,int low,int high,int zero,int one){\n if(l>high)\n return 0;\n if(dp[l]!=-1)\n return dp[l];\n int ans=0;\n if(l>=low && l<=high)\n ++ans;\n\n int op1=f(l+zero,low,high,zero,one...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\nint L,H,Z,O;\nint solve(int l,vector<int>&dp){\n if(l>H) return 0;\n if(dp[l]!=-1) return dp[l];\n int count=0;\n if(l>=L){\n count=1;\n }\n int a0=solve(l+Z,dp);\n int a1=solve(l+O,dp);\n return dp[l]= (a0+a1+count)%1000000007;\n\n}\n\n int countGoodStrings(int low, ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "const int MOD = 1e9 + 7;\n\nclass Solution {\npublic:\n\n int hi,lo, z,o;\n \n\n int helper(int ind, vector<int>& dp){\n if(ind > hi){\n return 0;\n }\n if(dp[ind] != -1) return dp[ind];\n\n int addZero = helper(ind + z,dp)%MOD;\n int addOne = helper(...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n int l, h;\n int mod = 1e9 + 7;\n\n int solverec(int len, int zero, int one, int dp[]) {\n if (len > h)\n return 0;\n\n if (dp[len] != -1)\n return dp[len];\n\n int ways = 0;\n\n ways = (ways + solverec(len + zero, zero, ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n\nint m=1e9+7;\n\nlong long int sumi(int n, int zero, int one, vector<long long int> &dp){\n if(n==0) return 1;\n if(n<0) return 0;\n if(dp[n]!=-1) return dp[n]%m;\n long long int a=0,b=0;\n if(n>=zero) a=sumi(n-zero,zero,one,dp)%m;\n if(n>=one) b=sumi(n-one,zer...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n long long dp[100100];\n long long mod = 1000000007;\n int rec(int low, int high, int zero, int one, long long length){\n if(length > high){\n return 0;\n }\n\n if(dp[length] != -1){\n return (dp[length] + mod) % mod;\n }...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int dp[1000001];\n int solve(int low, int high, int zero, int one,int cnt){\n if(cnt>high)return 0;\n if(dp[cnt]!=-1)\n return dp[cnt];\n dp[cnt]=(cnt>=low)?1:0;\n dp[cnt]+=solve(low,high,zero,one,cnt+zero);\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n long long fun(int low, int high, int zero, int one,int i,vector<long long>&dp){\n long long mod=1e9+7;\n if(i==0){\n return 1;\n }\n if(i<0){\n return 0;\n }\n if(dp[i]!=-1){\n return dp[i]%mod;\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n int l, h, z, o, mod = 1e9+7;\n vector<int> dp;\n int f(int i){\n if(i > h) return 0;\n if(dp[i]!=-1) return dp[i];\n int a = i>=l and i <= h ? 1 : 0;\n return dp[i] = (f(i+z) + f(i+o) + a) % mod;\n }\n int countGoodStrings(int low, int ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n long long int solve(int len,int zero,int one,vector<long long int>&dp,const int &MOD){\n if(len == 0)\n return 1;\n else if(len < 0)\n return 0;\n else if(dp[len] >= 0)\n return dp[len];\n\n long long int l = solve(...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "#define mode 1000000007\n\nclass Solution {\npublic:\n\n int helper(int low,int high,int zero,int one,int size,vector<int> &dp)\n {\n if(size > high) return 0;\n\n if(dp[size] != -1) return dp[size];\n\n int zerot = helper(low,high,zero,one,size+zero,dp);\n int onet = help...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n const int MOD=1e9+7;\n int solve(int len,int low,int high,int zero,int one,vector<int>& dp){\n if(len>high){\n return 0;\n }\n if(dp[len]!=-1){\n return dp[len];\n }\n int cnt = 0;\n if(len >= low){\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n const int MOD = 1e9 + 7;\n int f(int low, int high, int zeros, int ones, int currLen, vector<int> &dp){\n\n if(currLen > high) return 0;\n\n if (dp[currLen] != -1) return dp[currLen];\n\n int ans = 0;\n if(currLen >= low && currLen <= high){\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int recurssion(int low,int high,int zero,int one,int len,vector<int>&dp){\n if(len>high) return 0;\n bool flag=false;\n if(len>=low){\n flag=true;\n }\n if(dp[len]!=-1) return dp[len];\n int take=recurss...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int help(int curlen,int low,int high,int zero,int one,vector<int> &dp){\n if(curlen>high) return 0;\n if(dp[curlen]!=-1) return dp[curlen];\n int take=0;\n if(curlen>=low && curlen<=high) {\n take=1;\n }\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\npublic:\nint mod = 1000000007;\nint bfs(int low, int high, int zero, int one){\n int ans = 0;\n queue<int> q;\n q.push(0);\n while(!q.empty()){\n int length = q.front();\n q.pop();\n if(length > high){\n continue;\n }\n if(length >...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
2
{ "code": "class Solution {\n int count = 0;\n int mod = 1e9 + 7;\n int dp[1000000];\n int f(int low, int high, int zero, int one, int length) {\n if (length > high)\n return 0;\n if (dp[length] != -1) {\n return dp[length];\n }\n long long result = 0;\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\n int good_helper(int low, int high, int zero, int one, int curr_len, std::vector<int>& cache)\n {\n // std::cout << \"Helper with curr: \" << curr_len << std::endl;\n if (curr_len > high) return 0;\n if (cache[curr_len] != -1) return cache[curr_len];\n\...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\n int count = 0;\n int mod = 1e9 + 7;\n int dp[1000000];\n int f(int low, int high, int zero, int one, int length) {\n if (length > high)\n return 0;\n if (dp[length] != -1) {\n return dp[length];\n }\n long long result = 0;\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int rec(int low,int high,int zero,int one,int len,vector<int>& dp){\n //base case\n // if(len==high) return 1;\n if(len > high) return 0;\n if(dp[len] != -1) return dp[len];\n\n int fir;\n int two;\n \n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\n//recursion + memoization\nint mod=1e9+7;\nint f(int len,int low, int high, int zero, int one,vector<int> &dp)\n{\n if(len>high) return 0;\n if(dp[len]!=-1) return dp[len];\n\n int way1= f(len+zero,low,high,zero,one,dp);\n int way2= f(len+one,low,high,zero,one,dp);\n\...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\n int generate(const int &low, const int &high, const int &zero, const int &one, int zeroCnt, int oneCnt)\n {\n if ((zeroCnt + oneCnt) > high) return 0;\n\n if ((zeroCnt + oneCnt + zero) <= high && hash[zeroCnt + oneCnt + zero] == INT_MIN)\n {\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\n int generate(const int &low, const int &high, const int &zero, const int &one, int zeroCnt, int oneCnt)\n {\n if ((zeroCnt + oneCnt) > high) return 0;\n if ((zeroCnt + oneCnt + zero) <= high && hash[zeroCnt + oneCnt + zero] == INT_MIN)\n {\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\nprivate:\n long long helper(int length,int low,int high, int zero,int one,vector<long long>& dp) {\n long long mod = 1e9 + 7;\n if(length > high)// check for overflow\n return 0;\n if(dp[length] != -1) // check for already solved subproblems\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\nprivate:\n long long helper(int length,int low,int high, int zero,int one,vector<long long>& dp) {\n long long mod = 1e9 + 7;\n if(length > high)// check for overflow\n return 0;\n if(dp[length] != -1) // check for already solved subproblems\n ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\n\npublic:\n long long helper(int length,int high,vector<long long>& dp,int low,int zero,int one) {\n long long mod = 1e9 + 7;\n if(length > high) \n return 0;\n if(dp[length] != -1) \n return dp[length];\n dp[length] = length >= low ? ...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\n long long helper(int length,int high,vector<long long>& dp,int low,int zero,int one) {\n long long mod = 1e9 + 7; // mod\n\n if(length > high) // base case if the current index overflows\n return 0;\n\n if(dp[length] != -1) // check if the sub...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\n int MOD = 1e9 + 7;\npublic:\n int countGoodStrings(int low, int high, int zero, int one) {\n // string temp = \"\";\n int ans = 0;\n vector<int> dp(high+1,-1);\n ans = (ans + help(dp,0,low,high,zero,one)) % MOD;\n \n // return help(temp,high...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\n int mod = 1e9+7;\n int f(int currLen, int low, int high, int zeros, int ones,vector<int>& dp){\n if(currLen > high) return 0; \n if(dp[currLen] != -1) return dp[currLen];\n\n int left = f(currLen+zeros,low,high,zeros,ones,dp);\n int right = f(currLe...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\n const int MOD=1e9+7;\n int l = 0, r = 0, ans = 0;\n int f(int len, int a, int b,vector <long long>&dp) {\n if (len > r)\n return 0;\n if (dp[len]!=-1)\n return dp[len];\n long long c1 = 0, c2 = 0;\n c1 = (len + a >= l and l...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\n #define ll long long\npublic:\n ll mod=1e9+7;\n ll c(ll len,ll low,ll high,vector<ll>&dp,int zero,int one){\n if(len>high)return 0;\n if(dp[len]!=-1)return dp[len];\n ll ans=0;\n if(len>=low && len<=high)ans=1;\n ans +=c(len+zero,low,high,dp,ze...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\n #define ll long long\npublic:\n ll mod=1e9+7;\n ll c(ll len,ll low,ll high,vector<ll>&dp,int zero,int one){\n if(len>high)return 0;\n if(dp[len]!=-1)return dp[len];\n ll ans=0;\n if(len>=low && len<=high)ans=1;\n ans +=c(len+zero,low,high,dp,ze...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\n long long c = 0;\n long long MOD = 1e9 + 7;\n vector<long long> dp;\n\n int countGoodStrings(int low, int high, int zero, int one) {\n dp.resize(high + 1, -1);\n return backtrack(low, high, zero, one, 0);\n }\n\n long long backtrack(int low, int h...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int func(vector<int> &dp,int count,int low,int high, int zeroes,int ones)\n {\n if(count>high) return 0;\n\n if(dp[count]!=-1) return dp[count];\n\n if(count<=high && count>=low)\n {\n return dp[count]=(1+func(dp,c...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\n int dfs(vector<long long>& dp, int low, int high, int zero, int one, long long chars) {\n if (dp[chars] != -1)\n return dp[chars];\n\n long long ways = 0;\n if (chars >= low && chars <= high)\n ways = 1;\n\n ways = (ways + dfs...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int fun(string &s,int low,int high,int zero,int one,vector<int>&dp){\n if(s.size()>high) return 0;\n int ans=0;\n int len=s.size();\n if(dp[len]!=-1) return dp[len];\n if(s.size()>=low&&s.size()<=high) ans=1;\n s.a...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\nconst int MOD=1e9+7;\nint countGoodStrings(int low, int high, int zero, int one) {\n\tvector<vector<long long>> dp(2, vector<long long>(high + 1, 0));\n\tdp[1][one] = 1;\n\tdp[0][zero] = 1;\n\tlong long ans = 0;\n\tfor (int i = 1; i <= high; i++) {\n\t\tif (i - zero >= 0 && dp[0]...
2,562
<p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>&#39;0&#39;</code> <code>zero</code> times.</li> <li>Append th...
3
{ "code": "class Solution {\npublic:\nconst int MOD=1e9+7;\nint countGoodStrings(int low, int high, int zero, int one) {\n\tvector<vector<long long>> dp(2, vector<long long>(high + 1, 0));\n\tdp[1][one] = 1;\n\tdp[0][zero] = 1;\n\tlong long ans = 0;\n\tfor (int i = 1; i <= high; i++) {\n\t\tif (i - zero >= 0 && dp[0]...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
0
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n \nlong long sum=0;\n for(int i=0;i<nums.size();i++){\n \n sum=sum+nums[i];\n }\n int ans=-1;\nint m=INT_MAX;\nlong long sum2=0;\n for(int i=0;i<nums.size();i++){\n sum2=sum2+nums[i];\n ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
0
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(const vector<int>& nums) noexcept {\n ios_base::sync_with_stdio; cin.tie(nullptr); cout.tie(nullptr);\n long long int left_sum = nums[0], right_sum = 0;\n int left_size = 1, right_size = nums.size() - 1;\n for (int i = ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
0
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int n = nums.size();\n long long totalSum = 0;\n \n // Calculate total sum of the array\n for (int i = 0; i < n; ++i) {\n totalSum += nums[i];\n }\n\n long long lef...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
0
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n long long int left_sum = nums[0], right_sum = 0;\n int left_size = 1, right_size = nums.size() - 1;\n for (int i = 1; i < nums.size(); i++) {\n right_sum += nums[i];\n }\n long l...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
0
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n ios_base::sync_with_stdio; cin.tie(nullptr); cout.tie(nullptr);\n long long int left_sum = nums[0], right_sum = 0;\n int left_size = 1, right_size = nums.size() - 1;\n for (int i = 1; i < nums.siz...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
0
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n ios_base::sync_with_stdio; cin.tie(nullptr); cout.tie(nullptr);\n long long int left_sum = nums[0], right_sum = 0;\n int left_size = 1, right_size = nums.size() - 1;\n for (int i = 1; i < nums.siz...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
1
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n long long leftSum = 0 , rightSum = 0 , totalSum = 0;\n int minAverageElement = INT_MAX , ans = 0;\n int n = nums.size();\n cout<<n<<endl;\n for(int i = 0 ; i < n ; i++){\n\n totalSum += ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>&arr) {\n double sum=0;\n int n=arr.size();\n if(arr[0]==99999 && n>99999) return arr[0];\n if(n==0) return 0;\n if(n==1) return 0;\n\n for(int i=0;i<n;i++){\n sum+=(double)arr[i];\n ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int l=nums.size();\n long arr[l];\n long x=0;\n for(int i=0;i<l;i++)\n {\n x+=nums[i];\n arr[i]=x;\n }\n int ans=0;\n long temp=*max_element(nums....
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n if(nums.size() == 1) return 0;\n int size = nums.size();\n long long ans = 0 , min_avg = INT_MAX, prefix[size];\n prefix[0] = nums[0];\n for(int i = 1; i < size; i++) prefix[i] = nums[i] + ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n if(nums.size() == 1) return 0;\n int size = nums.size();\n long long ans = 0 , min_avg = INT_MAX, prefix[size];\n prefix[0] = nums[0];\n for(int i = 1; i < size; i++) prefix[i] = nums[i] + ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int n(nums.size()), res(n-1);\n long pre[n+1]; pre[0]=0;\n for (int i(0); i < n; ++i) pre[i+1] = pre[i]+nums[i];\n long dif = 1e9;\n for (int i(0); i < n; ++i) {\n long d = abs(p...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int n(nums.size()), res(n-1);\n long pre[n+1]; pre[0]=0;\n for (int i(0); i < n; ++i) pre[i+1] = pre[i]+nums[i];\n long dif = 1e9;\n for (int i(0); i < n; ++i) {\n long d = abs(p...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n \n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n int const n = nums.size();\n long dp_l[n];\n long dp_r[n];\n\n long sum_l = 0;\n long sum_r = 0;\n\n for ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int n=nums.size();\n long long pre[n],suf[n];\n pre[0]=nums[0];\n long long temp=nums[0];\n for(int i=1;i<n;i++){\n temp+=nums[i];\n pre[i]=temp;\n } \n for(int i=0;i<n-1;i++){\n suf...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int n=nums.size(); int index=0,min_num=INT_MAX;;\n long long pre_arr[n],suf_arr[n]; long long ans[n];\n long long sum=0;\n for(int i=0;i<n;i++){\n sum+=nums[i];\n pre_arr[i]=...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n long long t=accumulate(nums.begin(),nums.end(),0LL);\n long long cursum=0;\n vector<int> hen(nums.size());\n for(int i=0;i<hen.size();i++){\n cursum+=nums[i];\n long long j=c...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n long long int sum = 0; long long int preSum = 0;\n long long int n = nums.size();\n if(n == 1){\n return 0;\n }\n vector<int> ans(n);\n for(int i=0;i<n;i++){\n ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n#define ll long long \n int minimumAverageDifference(vector<int>& nums) {\n int n=nums.size();\n int ans=INT_MAX;\n int idx=0;\n vector<ll>presum(n+2,0);\n presum[0]=nums[0];\n for(int i=1;i<n;i++) presum[i]=presum[i-1]+nums[i];\n ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n long long mini=INT_MAX,ans=0;\n long long n=nums.size();\n vector<long long>pre(n,0);\n for(long long i=0;i<n;i++){\n pre[i]=(i>0?pre[i-1]:0)+nums[i];\n }\n for(long long ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int n = nums.size();\n int idx =-1;\n int avg = INT_MAX;\n long long l_sum=0 , total=0;\n vector<long long > left_sum(n) ;\n\n for(int i=0;i<n;i++)\n {\n total += nu...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n long long totsum=nums[0];\n vector<long long> temp(nums.size());\n temp[0]=nums[0];\n\n for(int i=1;i<nums.size();i++){\n totsum+=nums[i];\n temp[i] = temp[i-1] + nums[i];\n ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
2
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int n=nums.size(),ans=INT_MAX,index=-1;\n vector<long long> prefix(n,0);\n prefix[0]=nums[0];\n for(int i=1;i<n;i++)\n prefix[i]=prefix[i-1]+nums[i];\n for(int i=0;i<n;i++)\n ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
3
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& vec) {\n int len = vec.size();\n vector< long long >nums( len , -1);\n nums[0] = vec[0];\n for(int i=1 ; i<len ; i++) {\n nums[i] = vec[i] + nums[i-1];\n // cout << nums[i] << \" \";\n...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
3
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n const int SIZE = nums.size();\n if(SIZE == 1) return 0;\n\n vector<int> avg_right(SIZE);\n vector<int> avg_left(SIZE);\n\n long long sum = 0;\n for(int i = 0; i < SIZE; i++) {\n ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
3
{ "code": "class Solution {\npublic:\nlong long sum_right =0 ; //GLOBAL VARIABLE\nlong long sum_left = 0;\n\n\n\n//******************************************* Time Limit Exceeded **********************************************************************\n// long long mean(vector<int>& nums, int i)\...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
3
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n long long sum=0;\n for(auto num:nums)sum+=num;\n long long n1=0;\n vector<int>result;\n for(int i=0;i<nums.size();i++)\n {\n n1+=nums[i];sum-=nums[i];\n long lo...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
3
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int l=nums.size();\n vector<long long> sums(l); long long sum=0,i=0;\n for(long long q: nums)\n {\n sum+=q;\n sums[i++]=sum;\n }\n vector<int> absdiff(l);long l...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
3
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int n = nums.size();\n vector<int> abs(n);\n vector<long long> preSum(n);\n preSum[0] = nums[0];\n for (int i = 1; i < n; i++) {\n preSum[i] = preSum[i-1] + nums[i];\n }\n...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
3
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int n = nums.size();\n vector<int> absd(n);\n vector<long long> preSum(n);\n preSum[0] = nums[0];\n for (int i = 1; i < n; i++) {\n preSum[i] = preSum[i - 1] + nums[i];\n ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
3
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int n=nums.size();\n vector<long long>prefixsum(n);\n prefixsum[0]=nums[0];\n for(int i=1;i<n;i++){\n prefixsum[i]=prefixsum[i-1]+nums[i];\n }vector<long long>suffixsum(n);\n ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
3
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n long long mini = INT_MAX;\n int res = 0;\n int n = nums.size();\n vector<long long>prefix(n,nums[0]);\n vector<long long>suffix(n,nums[n-1]);\n for(int i=1;i<n;i++){\n pre...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
3
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int n = nums.size();\n int idx =-1;\n int avg = INT_MAX;\n long long l_sum=0 , r_sum=0 , total=0;\n vector<long long > left_sum(n) , right_sum(n);\n\n for(int i=0;i<n;i++)\n {...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
3
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int n = nums.size();\n vector<long long> suffix(n, 0);\n vector<long long> prefix(n, 0);\n int minIndex = 0;\n long long minDifference = LLONG_MAX;\n \n \n if (n == 1) {...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
3
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n\n int n=nums.size();\n\n if(n==1) return 0;\n\n vector<long long >prefix(n);\n vector<long long ...
2,342
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> <p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements o...
3
{ "code": "class Solution {\npublic:\n int minimumAverageDifference(vector<int>& nums) {\n int n = nums.size();\n vector<long long> preSum;\n long long sum =0;\n for(auto it:nums){\n sum += it;\n preSum.push_back(sum);\n }\n\n int ans = INT_MAX;\n ...
2,346
<p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p> <ul> <li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li> <li>It consists of only one unique digit.</li> </ul> <p>Return <em>t...
0
{ "code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int n=num.length();\n int val=-1;\n for(int i=0;i<=n-3;i++){\n if(num[i]==num[i+1]&& num[i]==num[i+2]){\n val=max(val,(num[i]-'0'));\n }\n }\n if(val==-1){\n ...
2,346
<p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p> <ul> <li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li> <li>It consists of only one unique digit.</li> </ul> <p>Return <em>t...
0
{ "code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int temp=INT_MIN;\n string res;\n int n=num.size();\n for(int i=0;i<n-2;i++){\n int j=i+1;\n int k=i+2;\n if(num[i]==num[j] && num[i]==num[k]){\n int x=num[i]...
2,346
<p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p> <ul> <li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li> <li>It consists of only one unique digit.</li> </ul> <p>Return <em>t...
0
{ "code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int nSize = num.length();\n int nMaxNum = -1;\n for (int i = 0; i < nSize-2; i++) {\n if (num[i] == num[i + 1] && num[i + 1] == num[i + 2]) {\n nMaxNum = max(nMaxNum, num[i] -'0');\n ...
2,346
<p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p> <ul> <li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li> <li>It consists of only one unique digit.</li> </ul> <p>Return <em>t...
0
{ "code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int mx = -1;\n for(int i = 2; i < num.size(); i++){\n if(num[i] == num[i - 1] && num[i] == num[i - 2]){\n if(mx < (num[i] - '0'))mx = (num[i] - '0');\n }\n }\n string st...
2,346
<p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p> <ul> <li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li> <li>It consists of only one unique digit.</li> </ul> <p>Return <em>t...
2
{ "code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int m=-3;\n for(int i=0;i<num.length()-2;i++)\n {\n if(num[i]==num[i+1] && num[i]==num[i+2])\n {\n if(m < int(num[i])-'0')\n m=int(num[i])-'0';\n\n i...
2,346
<p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p> <ul> <li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li> <li>It consists of only one unique digit.</li> </ul> <p>Return <em>t...
2
{ "code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n vector<string> v = {\"999\", \"888\", \"777\", \"666\", \"555\", \"444\", \"333\", \"222\", \"111\", \"000\"};\n for(string s: v){\n if(num.find(s) != string::npos){\n return s;\n }\n...
2,346
<p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p> <ul> <li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li> <li>It consists of only one unique digit.</li> </ul> <p>Return <em>t...
2
{ "code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int n = num.size();\n vector<int> prefix(n,1);\n\n string ans = \"\";\n\n for(int i = 1; i < n; i++){\n if(num[i] == num[i-1])\n prefix[i] = 1 + prefix[i - 1];\n }\n ...
2,346
<p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p> <ul> <li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li> <li>It consists of only one unique digit.</li> </ul> <p>Return <em>t...
2
{ "code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int n=num.size();\n string ans = \"\";\n for (int i = 0; i <= n - 3; i++) {\n if (num[i] == num[i + 1] && num[i] == num[i + 2]) {\n string triplet = num.substr(i, 3);\n if ...
2,346
<p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p> <ul> <li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li> <li>It consists of only one unique digit.</li> </ul> <p>Return <em>t...
2
{ "code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int k = 3;\n string ans;\n\n for (int i = 0; i <= num.size() - k; i++) {\n string cand;\n for (int j = i; j < i + 3; j++) {\n cand += num[j];\n }\n if (co...
2,346
<p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p> <ul> <li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li> <li>It consists of only one unique digit.</li> </ul> <p>Return <em>t...
2
{ "code": "class Solution {\npublic:\n string largestGoodInteger(string nums) {\n string result = \"\";\n \n for (int i = 0; i < nums.length(); i++) {\n if (nums[i] == nums[i + 1]) {\n if (nums[i + 1] == nums[i + 2]) {\n string triplet =nums.substr(...