id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size(), *prefix = new int[n], *suffix = new int[n], *diff = new int[n];\n for (int i = 0; i < n; i++) {\n diff[i] = gas[i] - cost[i];\n if (i == 0) prefix[0] = diff... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size();\n int total = 0;\n vector<int>sub(n,0);\n for(int i = 0;i<n;i++) {\n sub[i] = gas[i] - cost[i];\n total += sub[i];\n }\n if(tota... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n vector<int> dif;\n for(int i = 0;i<gas.size();i++){\n dif.push_back(gas[i]-cost[i]);\n }\n int total = 0;\n for(int i = 0;i<dif.size();i++){\n total+=dif[i... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int size = gas.size();\n vector<int> less;\n for(int i = 0 ;i< size ;i++)\n {\n less.push_back(gas[i] - cost[i]);\n }\n int res = 0;\n for(int i = 0; i<... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int size = gas.size();\n vector<int> less;\n for(int i = 0 ;i< size ;i++)\n {\n less.push_back(gas[i] - cost[i]);\n }\n int res = 0;\n for(int i = 0; i<... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n=gas.size();\n int res=-1;\n vector<int> sub;\n vector<int> indices;\n for(int i=0;i<n;i++){\n sub.push_back(gas[i]-cost[i]);\n // if(sub[i] >= 0) ind... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n vector<int> v;\n for(int i = 0;i<gas.size();i++){\n v.push_back(gas[i] - cost[i]);\n }\n int r = 0;\n for(auto x:v){\n r+=x;\n }\n if(r<0) re... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n vector<int>rem;\n int mx_balance=0;\n int mx_index=0;\n int sum=0;\n int balance;\n for(int i=0;i<gas.size();i++){\n balance=gas[i]-cost[i];\n rem.push_... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n=gas.size();\n vector<int> diff;\n int sum=0;\n for(int i=0;i<n;i++){\n diff.push_back(gas[i]-cost[i]);\n sum+=gas[i]-cost[i];\n }\n if(sum<0){... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int size = gas.size();\n vector<int> less;\n for(int i = 0 ;i< size ;i++)\n {\n less.push_back(gas[i] - cost[i]);\n }\n int res = 0;\n for(int i = 0; i<... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n if (accumulate(gas.begin(), gas.end(), 0) < accumulate(cost.begin(), cost.end(), 0)) {\n return -1;\n }\n\n priority_queue<int, vector<int>, std::greater<int>>pq;\n vector<i... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n if (accumulate(gas.begin(), gas.end(), 0) < accumulate(cost.begin(), cost.end(), 0)) {\n return -1;\n }\n\n priority_queue<int, vector<int>, std::greater<int>>pq;\n vector<i... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& A, vector<int>& B) {\n queue<pair<int,int>>q;\n \n int n=A.size();\n for(int i=0;i<n;i++){\n q.push({A[i]-B[i],i});\n }\n while(q.size()>1){\n if(q.front().first<0) q.pop();\n else{\n ... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n \n int n=gas.size();\n vector<int> left(n),right(n),temp;\n for(int i=0;i<n;i++){\n gas[i]-=cost[i];\n if(gas[i]>0) temp.push_back(i);\n }\n if(n==1... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size();\n std::vector<int> net(n);\n std::vector<long long> psum(n);\n\n long long min_psum = LONG_LONG_MAX;\n long long total_net = 0LL;\n\n\n for (int i = 0... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = cost.size();\n\n vector<int> aux(n);\n for(int i = 0; i < n; i++) {\n aux[i] = gas[i] - cost[i];\n }\n for(int i = 0; i < n; i++) {\n aux.push_back... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size();\n vector<int> gas_sum(n+1, 0);\n vector<int> cost_sum(n+1, 0);\n vector<int> min_diff(n+1, 2e9);\n for (int i = 1; i <= n; ++i) {\n gas_sum[i] = g... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size();\n vector<int> gas_sum(n, 0);\n vector<int> cost_sum(n, 0);\n vector<int> min_diff(n, 0);\n gas_sum[0] = gas[0];\n cost_sum[0] = cost[0];\n min_... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\n bool canComplete(vector<int>& diffTable, int startPoint){\n int thisPos = startPoint +1;\n if (thisPos == diffTable.size()){\n thisPos = 0;\n }\n int fuelLeft = diffTable[startPoint];\n //cout << \"Starting at: \" << startPoint << \"\\n\"... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size();\n vector<int> arr(2*n-1);\n int sum1 = 0, sum2 = 0;\n for(int i = 0; i<n; i++){\n arr[i] = gas[i]-cost[i];\n sum1 += gas[i];\n sum2... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int totalgas = 0;\n int totalcost = 0;\n int ret = -1;\n vector<int> valid;\n vector<int> diff;\n if(gas.size() == 1) {\n if(gas.at(0) >= cost.at(0)) {\n ... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n vector<int> a;\n for(int i=0;i<gas.size();++i){\n a.push_back(gas[i]-cost[i]);\n }\n int t=accumulate(a.begin(),a.end(),0);\n if(t<0) return -1;\n stack<int> s... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n \n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int sgas{},scost{};\n for(int i=0;i<gas.size();i++){\n sgas+=gas[i];\n }\n for(int i=0;i<gas.size();i++){\n scost+=cost[i];\n }\n if(scost>sga... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n vector<int> diff;\n vector<int> bits(gas.size(),0);\n for(int i=0;i<gas.size();i++) diff.push_back(gas[i]-cost[i]);\n int sum = 0;\n for(auto l:diff) sum+=l;\n if(su... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = cost.size();\n\n // diff vector (gas - cost)\n // if cum[0] < 0: return -1\n // search max number in cum, return integer\n\n vector<int> diff;\n for (int i = 0; i... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n=gas.size();\n vector<int> diff;\n int sumdiff=0;\n for(int i=0;i<n;i++){\n sumdiff+=gas[i]-cost[i];\n diff.push_back(gas[i]-cost[i]);\n }\n if... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n=gas.size();\n vector<int> diff;\n int sumdiff=0;\n for(int i=0;i<n;i++){\n sumdiff+=gas[i]-cost[i];\n diff.push_back(gas[i]-cost[i]);\n }\n if... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int ans=-1;\n void f(int start,int i,int tank,vector<int>& gas,vector<int>& cost,int n){\n if(i==2*n){\n ans=-1;\n return ;\n }\n if(start+n==i){\n ans=start;\n return ;\n }\n if(gas[i]+tank-cos... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int start = 0;\n int finish = 0;\n int size = gas.size() * 2;\n std::vector<int> new_gas(size);\n std::vector<int> new_cost(size);\n for (int i = 0; i < size / 2; ++i) {\... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "#define ll long long int\n#define un unsigned long long\n#define all(v) v.begin(),v.end()\n#define pb push_back\n#define sz(x) ((int)(x).size())\n\nclass Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n=sz(gas);\n vector<int> v(n),pref(n+1);\n ... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int start = 0;\n int finish = 0;\n int size = gas.size() * 2;\n std::vector<int> new_gas(size);\n std::vector<int> new_cost(size);\n for (int i = 0; i < size / 2; ++i) {\... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size();\n vector<int>res;\n for(int i = 0;i<n;i++){\n res.push_back(gas[i]-cost[i]);\n }\n res.insert(res.end(),res.begin(),res.end());\n res.resiz... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n vector<int> difference;\n int n = gas.size();\n\n for(int i = 0; i < n; i++)\n {\n int diff = gas[i] - cost[i];\n difference.push_back(diff);\n }\n\n ... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n vector<int> v = cost;\n for(auto a: cost){\n v.push_back(a);\n }\n\n vector<int>track(cost.size()*2);\n int g = gas[0];\n int count = 0;\n int index = 0... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n vector<int> v = cost;\n for(auto a: cost){\n v.push_back(a);\n }\n\n vector<int>track(cost.size()*2);\n int g = gas[0];\n int count = 0;\n int index = 0... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& A, vector<int>& B) {\n int n = A.size();\n vector<int> a = A;\n vector<int> b = B;\n \n for(int i = 0; i<n; i++){\n a.push_back(A[i]);\n b.push_back(B[i]);\n }\n \n int i = 0;\n int j = 0;\n \... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& A, vector<int>& B) {\n int n = A.size();\n vector<int> a = A;\n vector<int> b = B;\n \n for(int i = 0; i<n; i++){\n a.push_back(A[i]);\n b.push_back(B[i]);\n }\n \n int i = 0;\n int j = 0;\n \... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size();\n vector<int> starts;\n for(int i=0;i<n;i++){\n if(gas[i]>=cost[i])\n starts.push_back(i);\n }\n for(int i=0;i<n-1;i++){\n ... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n priority_queue<pair<int,int>> maxHeap;\n vector<int> diff;\n int sum=0;\n for(int i=0;i<gas.size();i++){\n maxHeap.push({gas[i]-cost[i],i});\n diff.push_back(gas[... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int sum_gas=0;\n int sum_cost=0;\n int maxi=0;\n int n=gas.size();\n vector<pair<int,int>>diff;\n for(int i=0;i<gas.size();i++){\n sum_gas+=gas[i];\n ... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "// greedy approach.. Two-pointer se bhi ho skta hai but usme while loop ki conditions ka thoda dhyan rkhna pdega.. not that straightforward to remember (https://www.geeksforgeeks.org/problems/circular-tour-1587115620/1?itm_source=geeksforgeeks&itm_medium=article&itm_campaign=practice_card) \n\nclass Soluti... |
134 | <p>There are <code>n</code> gas stations along a circular route, where the amount of gas at the <code>i<sup>th</sup></code> station is <code>gas[i]</code>.</p>
<p>You have a car with an unlimited gas tank and it costs <code>cost[i]</code> of gas to travel from the <code>i<sup>th</sup></code> station to its next <code>... | 1 | {
"code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size();\n int i = 0, prev = 0, sum = 0;\n while (i < n) {\n sum = sum + gas[i] - cost[i];\n if (sum < 0) {\n sum = 0, prev = i+1;\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "// class Solution {\n// public:\n// int candy(vector<int>& ratings) {\n// int n=ratings.size();\n// vector<int>left(n);\n// vector<int>right(n);\n\n// left[0]=1;\n// for(int i=1;i<n;i++){\n// if(ratings[i]>ratings[i-1]){\n// left[i]=le... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int sum=1, i=1; int n=ratings.size();\n while(i<n){\n if(ratings[i]==ratings[i-1]){\n sum++;i++;continue;\n }\n int peak=1;\n while(i<n && ratings[i]>ratings[i-1]){\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "/*\nclass Solution {\npublic:\n int candy(vector<int>& ratings) {\n int L = ratings.size();\n vector<int> levels(L, 0);\n vector<int> candies(L, 1);\n\n levels[0] = 0;\n \n // for(int i = 1; i < L; i++)\n // {\n // if(ratings[i] == ratings[i - ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int sum=1;\n int i=1; int n=ratings.size();\n int peak;int down;\n while(i<n){\n if(ratings[i]==ratings[i-1]){\n sum=sum+1;\n i++;\n continue;\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "class Solution {\npublic:\n int candy(std::vector<int>& ratings) {\n int n = ratings.size();\n int ret = 1;\n int up = 0;\n int down = 0;\n int peak = 0; //record height from the peak(except peak node) \n for(int i =1;i<n;i++)\n {\n int temp =... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "class Solution {\npublic:\n int candy(std::vector<int>& ratings) {\n int n = ratings.size();\n int ret = 1;\n int up = 0;\n int down = 0;\n int peak = 0; //record height from the peak(except peak node) \n for(int i =1;i<n;i++)\n {\n int temp =... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "class Solution {\npublic:\n int candy(std::vector<int>& ratings) {\n int n = ratings.size();\n int ret = 1;\n int up = 0;\n int down = 0;\n int peak = 0; //record height from the peak(except peak node) \n for(int i =1;i<n;i++)\n {\n int temp =... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n=ratings.size();\n int total=n, i=1;\n\n while(i<n){\n if(ratings[i]==ratings[i-1]){\n i++;\n continue;\n }\n int peak=0;\n while(ratings[i]... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "class Solution {\npublic:\n int candy(std::vector<int>& ratings) {\n int n = ratings.size();\n int ret = 1;\n int up = 0;\n int down = 0;\n int peak = 0;\n for(int i =1;i<n;i++)\n {\n int temp = ratings.at(i)-ratings.at(i-1);\n if(te... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "#pragma GCC optimize(\"Ofast\")\nstatic auto _ = [] () {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);return 0;}();\nclass Solution {\npublic:\n int candy(vector<int>& ratings) {\n int sum = 1, i = 1, n = ratings.size();\n while(i < n){\n if(ratings[i] == r... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n=ratings.size();\n int left[n];\n int right[n];\n int count=2;\n left[0]=1;\n for(int i=1;i<n;i++){\n if(ratings[i]>ratings[i-1]){\n left[i]=count;\n c... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int res=0;\n int n=ratings.size();\n int lft[n];\n int rt[n];\n lft[0]=0;\n rt[n-1]=0;\n for(int i=1;i<ratings.size();i++)\n {\n if(ratings[i-1]<ratings[i])\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "class Solution {\npublic:\n int candy(std::vector<int>& ratings) {\n int n = ratings.size();\n std::vector<int> candies(n, 1);\n\n for (int i = 1; i < n; ++i) {\n if (ratings[i] > ratings[i - 1]) {\n candies[i] = candies[i - 1] + 1;\n }\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "class Solution {\npublic:\n int candy(std::vector<int>& ratings) {\n int n = ratings.size();\n if (n == 0) return 0;\n\n std::vector<int> candies(n, 1); // 初始化,每个孩子至少 1 个糖果\n\n // 从左到右遍历,如果右边的孩子评分比左边的高,糖果数加 1\n for (int i = 1; i < n; i++) {\n if (ratings[i]... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "#include <vector>\n#include <algorithm> // for max function\nusing namespace std;\n\nclass Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n = ratings.size();\n vector<int> candies(n, 1); // Each child gets at least one candy\n\n // Left to right pass\n for (int... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 0 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n vector<int> counts (ratings.size(), 1);\n\n // left part\n for (int i = 1; i < ratings.size(); i++){\n if (ratings[i] > ratings[i - 1]){\n counts[i] = counts[i - 1] + 1;\n // cou... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 1 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& arr) \n {\n int n=arr.size(),ans=0;\n vector<int> candy(n,1);\n \n for(int i=1;i<n;i++)\n {\n if(arr[i]>arr[i-1])\n candy[i]=candy[i-1]+1;\n }\n \n for(int i=n-1;i>0;i-... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 1 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n = ratings.size();\n vector<int> candies(n, 1);\n for(int i=1;i<n;i++){\n if(ratings[i]> ratings[i-1] && candies[i]<=candies[i-1]){\n candies[i] = candies[i-1] +1;\n }\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 1 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n = ratings.size();\n vector<int> candy(n, 1);\n for (int i = 1; i < n; i++) {\n if (ratings[i - 1] < ratings[i])\n candy[i] = candy[i - 1] + 1;\n }\n\n for (int i = n - 2; i ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 1 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n=ratings.size();\n vector<int> out(n,1);\n for(int i=1;i<n;i++){\n if(ratings[i]>ratings[i-1]){\n out[i]=out[i-1]+1;\n }\n\n }\n for(int i=n-2;i>=0;i--){\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 2 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n\n vector<int> candies(ratings.size(),1);\n \n for(int i=1 ; i<ratings.size() ; i++)\n if(ratings[i-1]<ratings[i]) candies[i] = candies[i-1]+1;\n \n for(int i=ratings.size()-2 ; i>=0 ; i--)\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 2 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n = ratings.size();\n vector<int> candies(n, 1); // Step 1: Initialize all children with 1 candy\n\n // Step 2: Left-to-right pass\n for (int i = 1; i < n; i++) {\n if (ratings[i] > ratings[i - 1]... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 2 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n=ratings.size();\n \n int left=0;\n vector<int> prefix(n, 1);\n vector<int> suffix(n, 1); \n\n for(int i=1; i<n; i++)\n {\n if(ratings[i-1] < ratings[i])\n {\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 2 | {
"code": "class Solution{\npublic:\n\tint candy(vector<int> &ratings){\n\t\tint numChildren = ratings.size();\n vector<int> minCandies(numChildren,0);\n vector<int> minimas;\n\n //edges\n if(numChildren == 1){\n return 1;\n }\n if(numChildren >= 2 && ratings[1] >=... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 2 | {
"code": "class Solution {\n public:\n int candy(vector<int>& ratings) {\n const int n = ratings.size();\n int ans = 0;\n vector<int> l(n, 1);\n vector<int> r(n, 1);\n\n for (int i = 1; i < n; ++i)\n if (ratings[i] > ratings[i - 1])\n l[i] = l[i - 1] + 1;\n\n for (int i = n - 2; i >= 0... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 2 | {
"code": "\nclass Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n = ratings.size();\n int sum = 0;\n vector<int> left(n,1);\n vector<int> right(n,1);\n for(int i=1;i<n;i++)\n {\n if(ratings[i] > ratings[i-1])\n {\n left... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\n\n public:\n\n int candy(vector<int>& ratings) {\n\n const int n = ratings.size();\n\n int ans = 0;\n\n vector<int> l(n, 1);\n\n vector<int> r(n, 1);\n\n for (int i = 1; i < n; ++i)\n\n if (ratings[i] > ratings[i - 1])\n\n l[i] = l[i - 1] + 1;\n\n for (int i... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& nums) {\n \n int n = nums.size();\n vector<int> left(n,1);\n vector<int> right(n,1);\n\n for(int i =1 ; i<n ; i++)\n {\n if(nums[i]>nums[i-1]){\n left[i] = left[i-1]+1;\n }\n... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n = ratings.size();\n\n vector<int> left(n,1);\n vector<int> right(n,1);\n\n for(int i = 1; i < n; i++){\n if(ratings[i-1] < ratings[i]){\n left[i] = left[i-1] + 1;\n }\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int prev = 0;\n int n = ratings.size();\n vector<int> left(n , 0);\n vector<int> right(n , 0);\n left[0] = 1;\n right[n-1] = 1;\n\n for(int i = 1 ; i < n ; i++){\n if(ratings[i] > ratings[... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n = ratings.size();\n vector<int> left(n, 1);\n vector<int> right(n, 1);\n\n for (int i = 1; i < n; i++) {\n if (ratings[i] > ratings[i-1]) left[i] = left[i-1]+1;\n }\n for (int i = n... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n = ratings.size();\n vector<int> bigger(n, 0);\n vector<int> smaller(n, 0);\n for (int i = 1; i < n; i++) {\n if (ratings[i] > ratings[i - 1]) {\n bigger[i] = bigger[i - 1] + 1;\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n vector<int> ans = {1};\n for (int i = 1; i < ratings.size(); i++) {\n if (ratings[i] > ratings[i-1]) {\n ans.push_back(ans[i-1] + 1);\n } else {\n ans.push_back(1);\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& arr) {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n int n = arr.size();\n vector<int> left(n, 1), right(n, 1);\n\n for (int i = 1; i < n; i++) {\n if (arr[i] > arr[i-1]) left[i] ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n void printVec(vector<int> vec) {\n for(int i=0;i<size(vec);i++)\n cout << vec[i] << \" \";\n cout << endl;\n }\n int candy(vector<int>& ratings) {\n int n = size(ratings);\n vector<int> cnts(n, 1);\n vector<int> V(n);\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n if(!ratings.size()) return 0;\n if(ratings.size()==1) return 1;\n int sum=1;\n bool isRev = false;\n int lastMax = 1;\n vector<int> candy;\n candy.push_back(1);\n for(int i=1;i<ratings... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& arr) {\n // max == 1\n // min == -1\n // mind == 0\n // maxd == 2\n int n = arr.size();\n if(n==1) return 1;\n vector<pair<int,int>> v;\n vector<int> slopes;\n if(arr[0]>arr[1]) {v.push_back... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution \n{\npublic:\n int candy(vector<int>& ratings) \n {\n int n = ratings.size();\n\n vector <int> left(n);\n vector <int> right(n);\n\n left[0] = 1;\n right[n - 1] = 1;\n\n for(int i = 1; i < n; i++)\n {\n if(ratings[i] > ratings... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n=ratings.size();\n vector<int> leftDistribution(n,1);\n vector<int> rightDistribution(n,1);\n vector<int> maxi(n);\n\n for (int i=1;i<n;i++){\n if (ratings[i]>ratings[i-1]){\n ... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\n void rec(vector<int>& ratings, int n, int isVis[], int candies[], int& ans, int index) {\n if (isVis[index]) {\n return;\n }\n isVis[index] = 1;\n if (index > 0 && ratings[index] > ratings[index-1]) {\n candies[index] = candies[index-1... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n int candy(vector<int>& ratings) {\n int n = ratings.size();\n vector<int> slopeMax(n);\n queue<int> qq;\n qq.push(0);\n for (int i = 1; i < n; i++) {\n if (!(ratings[i] < ratings[i - 1])) {\n while (!qq.empty()) {\n... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n \n int candy(vector<int>& ratings) {\n int n=ratings.size();\n if(n==1) return 1;\n\n vector<int> candies(n, 0);\n vector<int> index;\n\n for(int i=0; i<n; i++){\n index.push_back(i);\n }\n\n sort(index.begin(), i... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n int extra_space_approach(vector<int> ratings) {\n // if increasing seq is present -> then we can get the answer -> by comparing element with its left neighbor (left -> right)\n\n // if decreasing seq is present -> then we can get the answer -> by comparing eleme... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n \n \n void calcCandies(vector<int>& ratings, vector<int> &candies, int crt, int min, int n) {\n if(crt == n - 1) {\n candies[crt] = min;\n return ;\n } \n\n if(ratings[crt] == ratings[crt + 1]) {\n calcCandies(rating... |
135 | <p>There are <code>n</code> children standing in a line. Each child is assigned a rating value given in the integer array <code>ratings</code>.</p>
<p>You are giving candies to these children subjected to the following requirements:</p>
<ul>
<li>Each child must have at least one candy.</li>
<li>Children with a high... | 3 | {
"code": "class Solution {\npublic:\n \n \n void calcCandies(vector<int>& ratings, vector<int> &candies, int crt, int min, int n) {\n if(crt == n - 1) {\n candies[crt] = min;\n return ;\n } \n\n if(ratings[crt] == ratings[crt + 1]) {\n calcCandies(rating... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 0 | {
"code": "const static auto io_speed_up = []() {\n std::ios::sync_with_stdio(0);\n cin.tie(0);\n FILE *fptr = fopen(\"user.out\", \"w\");\n int x, out = 0;\n while (!cin.eof()) {\n if (cin.peek() == '[') cin.ignore();\n else break;\n out = 0;\n while (cin.peek() != ']') {\n... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 0 | {
"code": "const static auto io_speed_up = []() {\n std::ios::sync_with_stdio(0);\n cin.tie(0);\n FILE *fptr = fopen(\"user.out\", \"w\");\n int x, out = 0;\n while (!cin.eof()) {\n if (cin.peek() == '[') cin.ignore();\n else break;\n out = 0;\n while (cin.peek() != ']') {\n... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 0 | {
"code": "// class Solution {\n// public:\n// int singleNumber(vector<int>& nums)\n// { int n = nums[0];\n// ios::sync_with_stdio(false);\n// cin.tie(nullptr);\n// cout.tie(nullptr);\n// for(int i = 1; i < nums.size(); i++){\n// n ^= nums[i];\n// }\n// ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\ninline bool isdigit(char c) {\n return c >= '... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int n=nums.size();\n for(int i=0;i<n;i++)\n {\n int count=0;\n for(int j=0;j<n;j++)\n {\n if(nums[i]==nums[j])\n count++;\n }\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums){\n int res=0;\n for(int i:nums){\n res^=i;\n }\n return res;\n }\n};",
"memory": "19100"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& xs) {\n int ans = 0;\n for (auto x : xs) ans ^= x;\n return ans;\n }\n};",
"memory": "19200"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& arr) {\n \n int ans=0;\n for(int i=0;i<arr.size();i++){\n ans=ans^arr[i];\n }\n return ans;\n }\n};",
"memory": "19200"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int ans=nums[0];\n for(int i=1;i<nums.size();i++){\n ans^=nums[i];\n }\n return ans;\n }\n};",
"memory": "19300"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int xorr = 0;\n for(int i = 0; i<nums.size(); i++){\n xorr = xorr ^ nums[i];\n }\n return xorr; \n }\n};",
"memory": "19300"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int ans=0;\n for(int val :nums){\n ans= ans ^ val;\n }\n return ans;\n }\n};",
"memory": "19400"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int res=0;\n for(int i = 0; i < nums.size(); i++) \n {\n \n res=res^nums[i];\n }\n return res;\n }\n};",
"memory": "19400"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int n = nums.size();\n int ans = nums.at(0);\n for(int i = 1; i < n; i++){\n ans = ans^nums[i];\n }\n\n return ans;\n }\n};",
"memory": "19500"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.