id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int minCut(string&s) {\n int n=s.length();\n vector<int>dp(n,0);\n vector<vector<int>>is_pal(n, vector<int>(n,0));\n for(int i=n-1 ; i>=0 ; i--){\n for(int j=i ; j<n ; j++){\n if(i==j) is_pal[i][j]=1;\n else...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n //int ispalli(int i, int j, string s){\n //// while(j>i ){\n // if(s[i]==s[j]){\n // i++;\n // j--;\n // }\n // else{\n // return false;\n // }\n //}\n // return true;\n //...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\n bool check(string &s, int i, int j, vector<vector<int>> &x){\n int a=i,b=j;\n if(x[a][b]!=-1) return x[a][b];\n while(i<=j){\n if(s[i]!=s[j]) return x[a][b]= 0;\n i++; j--;\n }\n\n return x[a][b]= 1;\n }\n\n int fun(string...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n //int ispalli(int i, int j, string s){\n //// while(j>i ){\n // if(s[i]==s[j]){\n // i++;\n // j--;\n // }\n // else{\n // return false;\n // }\n //}\n // return true;\n //...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int minCut(string s) {\n int n = s.size();\n //length , start index\n vector<vector<int>> dp(n+1,vector<int>(n+1,0));\n for(int i = 0; i<=n; i++){\n for(int j = 0; j<=n-i; j++){\n if(i == 0 || i == 1){\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n bool isPal(string& str, int s, int e, vector<vector<int>>& isPaldp) {\n if (s >= e) return true; // Correct base case for palindrome check\n\n if (isPaldp[s][e] != -1) return isPaldp[s][e];\n\n if (str[s] == str[e]) {\n return isPaldp[s][e] = i...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n\n vector<vector<int>> dp1;\n vector<int> dp2;\n int n;\n string t; \n bool partition(int l, int r)\n {\n if(l>= r)\n {\n return 1;\n }\n if(dp1[l][r] != -1)\n {\n return dp1[l][r];\n }\n int...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\n bool isPalindrome(string& s, int start, int end) {\n int i = start, j = end;\n while (start <= end) {\n if (s[start] != s[end]) {\n return false;\n }\n start++, end--;\n }\n return true;\n }\n int solve(...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int n;\n\n bool isPalindrome(int i, int j, string &s, vector<vector<int>> &memo)\n {\n if(memo[i][j] != -1)\n return memo[i][j];\n\n if(i == j)\n return memo[i][j] = true;\n\n while(i < j)\n {\n if(s[i] == s[j])\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int n;\n\n bool isPalindrome(int i, int j, string &s, vector<vector<int>> &memo)\n {\n if(memo[i][j] != -1)\n return memo[i][j];\n\n if(i == j)\n return memo[i][j] = true;\n\n while(i < j)\n {\n if(s[i] == s[j])\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n bool check(int i,int j,string &s,vector<vector<int>> &dp){\n if(i > j) return 1;\n\n if(dp[i][j] != -1) return dp[i][j];\n if(s[i] == s[j]) return dp[i][j] = check(i+1,j-1,s,dp);\n return dp[i][j] = 0;\n }\n int solve(int i,int n,string &s,ve...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n bool checkPalindrme(string &s,int l,int m){\n int i=l,j=m;\n while(i<=j){\n if(s[i]!=s[j]){\n return false;\n }\n i+=1;\n j-=1;\n }\n return true;\n }\n int rec(int i,int j,string &s,...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n bool isvalid(string &s,int i,int j,vector<vector<int>> &dp2)\n {\n if(dp2[i][j]!=-1)return dp2[i][j];\n int ci = i, cj = j;\n while (i < j && i < s.size() && i >= 0 && j < s.size() && j >= 0) {\n if (dp2[i][j] != -1) return dp2[ci][c...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\nprivate:\n\n int solve2(string s,vector<vector<int>>&palindromes)\n {\n int n=s.length();\n vector<int>dp(n+1,0);\n dp[n]=-1;\n for(int start=n-1;start>=0;start--)\n {\n string temp=\"\";\n int ans=INT_MAX;\n for(in...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n int mem[2005];\n int solve(int i,string &s){\n int n=s.length();\n if(i==n)return 0;\n if(mem[i]!=-1)return mem[i];\n int ans=1e9;\n for(int k=i;k<n;k++){\n if(dp[i][k]){\n if(k!=n-1)...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\nint dp[2003];\n bool computePalindrome(int i, int j, string &s,vector<vector<int>> &palindrome ){\n if(i>=j){\n return palindrome[i][j]=1;\n }\n if(palindrome[i][j]!=-1) return palindrome[i][j];\n bool x=0;\n if(s[i]=...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n\n int rec(int idx, string & s, vector<int> & dp, vector<vector<int>> & adj)\n {\n if (idx==s.size()) return 0;\n if (dp[idx]!=-1) return dp[idx];\n string curr = \"\";\n int mn = 1e7;\n for (int i=idx; i<s.size(); i++)\n {\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int minCut(string s) {\n int n = s.size();\n vector<vector<bool>> isPalindrome(n, vector<bool>(n, false));\n vector<vector<int>> minCuts(n, vector<int>(n, 0));\n\n // Initialize the isPalindrome table\n for (int length = 1; length <= n; ++le...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\n int n;\n vector<vector<bool>> palin;\n vector<vector<int>> dp;\n\n bool isPalindrome(string &s, int i, int j){\n while(i < j) if(s[i++] != s[j--]) return 0;\n return 1;\n }\n\n void fill_palin(string &s){\n for(int i = 0; i < n; i++) palin[i][i] = 1...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(string s,int i,int j,vector<vector<int>> &palindrome){\n if (i >= j) return palindrome[i][j]=true;\n if (palindrome[i][j] != -1) return palindrome[i][j];\n if (s[i] == s[j]) return palindrome[i][j] = isPalindrome(s, i + 1, j - 1,palindro...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\n int n;\n vector<vector<bool>> palin;\n vector<vector<int>> dp;\n\n bool isPalindrome(string &s, int i, int j){\n while(i < j) if(s[i++] != s[j--]) return 0;\n return 1;\n }\n\n void fill_palin(string &s){\n for(int i = 0; i < n; i++) palin[i][i] = 1...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int dp[2001][2001];\n int solve(int left,int right,vector<vector<int>>&pal){\n if(left>=right) return 0;\n if(dp[left][right]!=-1) return dp[left][right];\n if(pal[left][right]) return dp[left][right]=0;\n int ans=INT_MAX;\n for(int k=lef...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int minCut(string s) {\n vector<vector<double>> map;\n vector<int> minCuts;\n map.push_back({0});\n minCuts.push_back(0);\n for(int i = 1; i < s.length(); i++) {\n int maxCut = minCuts[minCuts.size() - 1] + 1;\n if(s[i]...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int minCut(string s) {\n vector<vector<double>> map;\n vector<int> minCuts;\n map.push_back({0});\n minCuts.push_back(0);\n for(int i = 1; i < s.length(); i++) {\n int maxCut = minCuts[minCuts.size() - 1] + 1;\n if(s[i]...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n\n int minCut(string s) {\n ll n = s.length();\n vector<vector<ll> > v(n);\n for(ll i=0; i<n; i++){\n v[i].push_back(i);\n ll id1 = i-1;\n ll id2 = i+1;\n while(id1>=0 && id2<n){\n ...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n\n bool isPalindrome(string &s, int i, int j){\n while(i < j){\n if(s[i] != s[j]){\n return false;\n }\n i++;\n j--;\n }\n return true;\n }\n\nint solve(string s, int i, int j, vector<vector<int>>&...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(string &s,int i,int j){\n int st=i;\n int e=j;\n while(st<e){\n if(s[st]!=s[e])return false;\n st++;\n e--;\n }\n return true;\n }\n int f(int i,int j,string &s, vector<vector<int>>&d...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n int dp[2001];\n vector<vector<int>>m;\n /*bool palin(string &s,int st,int en){\n int len=en-st+1;\n string t=\"\";\n for(int i=st;i<=en;i++) t.push_back(s[i]);\n for(int i=0;i<t.size()/2;i++){\n if(t[i]!=t[t.size()-i-1]) return fal...
132
<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p> <p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</c...
3
{ "code": "class Solution {\npublic:\n bool ispalin(string &s) {\n int i = 0;\n int j = s.length() - 1;\n\n while (i < j) {\n if (s[i] != s[j]) {\n return false;\n }\n i++;\n j--;\n }\n return true;\n }\n\n int solv...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
0
{ "code": "\nstatic const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n return 0;\n}();\nint init = []{\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for(string str;getline(cin,str);){\n cout<<str<<\"\\n\";\n }\n exit(0);\n return 0;\n}();\ncla...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
0
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
0
{ "code": "\nstatic const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n return 0;\n}();\nint init = []{\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for(string str;getline(cin,str);){\n cout<<str<<\"\\n\";\n }\n exit(0);\n return 0;\n}();\ncla...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
0
{ "code": "#include <iostream>\n#include <algorithm>\n#include <unordered_map>\nstatic const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n return 0;\n}();\nint init = []{\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for(string str;getline(cin,str);){\n ...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
0
{ "code": "#include <iostream>\n#include <algorithm>\n#include <unordered_map>\nstatic const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n return 0;\n}();\nint init = []{\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for(string str;getline(cin,str);){\n ...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
0
{ "code": "#include <iostream>\n#include <algorithm>\n#include <unordered_map>\nstatic const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n return 0;\n}();\nint init = []{\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for(string str;getline(cin,str);){\n ...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
0
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
0
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
0
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
0
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
1
{ "code": "class Solution\n{\npublic:\n Node *cloneGraph(Node *node)\n {\n if (!node)\n return node;\n unordered_map<Node *, Node *> mp;\n mp[nullptr] = nullptr;\n clone(node, mp);\n return mp[node];\n }\n\n void clone(Node *node, unordered_map<Node *, Node *>...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
1
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
1
{ "code": "class Solution\n{\npublic:\n Node *cloneGraph(Node *node)\n {\n if (!node)\n return node;\n unordered_map<Node *, Node *> mp;\n mp[nullptr] = nullptr;\n clone(node, mp);\n return mp[node];\n }\n\n void clone(Node *node, unordered_map<Node *, Node *>...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
1
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
2
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
2
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
2
{ "code": "class Solution {\npublic:\n Node *cloneGraph(Node *node) {\n if (node == nullptr) {\n return nullptr;\n }\n unordered_map<Node *, Node *> cloned;\n return cloneNode(node, cloned);\n }\n Node *cloneNode(Node *node, unordered_map<Node *, Node *> &cloned) {\n\n if (cloned.find(node) != ...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
2
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
3
{ "code": "class Solution {\npublic:\n Node* cloneGraph(Node* node) {\n unordered_map<Node* , Node*> mp;\n\n if (!node) {\n return node;\n }\n\n return dfs(node, mp);\n }\n\n Node* dfs(Node* node, unordered_map<Node* , Node*>& mp) {\n if (mp.find(node) != mp.end(...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
3
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
3
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
3
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
3
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
133
<p>Given a reference of a node in a <strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong> undirected graph.</p> <p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone...
3
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> neighbors;\n Node() {\n val = 0;\n neighbors = vector<Node*>();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector<Node*>();\n }\n Node(int _val, vector<Node*> _neighbors)...
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>...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nint parse_input_and_solve(const std::string& gas, const std::string& cost) {\n const int N = gas.size();\n const int M = cost.size();\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>...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nint parse_input_and_solve(const std::string& gas, const std::string& cost) {\n const int N = gas.size();\n const int M = cost.size();\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>...
0
{ "code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size();\n int total_surplus = 0; // it will give us a difference b/w gas & cost\n int surplus = 0; // our tank\n int start = 0; // and the index of gas station\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>...
0
{ "code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n=gas.size();\n int total_gas=0;\n int total_cost=0;\n int starting_point=0;\n int curr=0;\n for(int i=0;i<n;i++){\n total_gas=total_gas+ga...
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>...
0
{ "code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size();\n int totalGas =0;\n int totalCost =0;\n\n for(int i=0; i<n; i++){\n totalGas += gas[i];\n totalCost += cost[i];\n }\n if(totalG...
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>...
0
{ "code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size();\n int total_difference {0};\n int difference {0};\n int start = 0;\n for(int i{0}; i < n; ++i){\n total_difference += gas[i] - cost[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>...
0
{ "code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int deficit = 0;\n int balance = 0;\n int ans = 0;\n\n for(int i = 0; i < gas.size(); ++i){\n balance += gas[i] - cost[i];\n\n if(balance < 0){\n d...
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>...
0
{ "code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n for(int i=0;i<gas.size();i++)\n {\n cost[i]=gas[i]-cost[i];\n }\n int res=0;\n for(int i=0;i<cost.size();i++)\n {\n res+=cost[i];\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>...
0
{ "code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& a, vector<int>& c) {\n int n=a.size();\n int ans=0;\n int sum=0;\n for(int i=0;i<n;i++)\n {\n sum+=a[i];\n if(sum<c[i])\n {\n sum=0;\n ans=i+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>...
0
{ "code": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n \n int balance=0;\n int deficit=0;\n int start=0;\n\n for(int i=0;i<gas.size();i++){\n balance+=gas[i]-cost[i];\n\n if(balance<0){\n deficit...
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 position =0,sum=0,total=0;\n for(int i=0;i<gas.size();i++){\n sum+=gas[i]-cost[i];\n if(sum<0){\n total+=sum;\n sum=0;\n pos...
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 for(int i=0;i<gas.size();i++)\n {\n cost[i]=gas[i]-cost[i];\n }\n int res=0;\n for(int i=0;i<cost.size();i++)\n {\n res+=cost[i];\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 int start = 0;\n int end = start;\n int g = 0;\n bool cycle = false;\n bool found = false;\n vector<bool> visited(gas.size(), false);\n while(!cycle && !found){\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 trav[gas.size()+1]; trav[0] = 0; int minind = 0;//const int n = gas.size();\n for(int i = 0; i < gas.size(); i++)\n {\n trav[i+1] = trav[i]+gas[i]-cost[i];\n if (tra...
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 pref[100005]={0};\n for(int i=0;i<gas.size();i++)\n {\n\n pref[i]=gas[(i)%(gas.size())]-cost[i];\n }\n int s=0;\n int prev=0;\n int last=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 int sav[n+1];\n int sum=0;\n for(int i=0;i<n;i++){\n sav[i+1]=gas[i]-cost[i];\n sum+=sav[i+1];\n }\n if(sum<0)return -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 n = gas.size();\n \n int startPos = 0;\n for (int i = 0; i < n; i++) {\n if (gas[i] - cost[i] >= 0) {\n startPos = i;\n break;\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 \n int startPos = 0;\n for (int i = 0; i < n; i++) {\n if (gas[i] - cost[i] >= 0) {\n startPos = i;\n break;\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 if(gas==cost)\n {\n return 0;\n }\n int g=gas.size();\n vector<int> startedIndex;\n \n for(int i =0 ; i<g;i++)\n {\n if(gas[i]-c...
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 g = accumulate(gas.begin(), gas.end(), 0);\n int c = accumulate(cost.begin(), cost.end(), 0);\n if(c>g)\n return -1;\n deque<int>q;\n int remainGas = 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> start_points(gas.size());\n int balance = 0;\n for(int i = gas.size()-1; i >= 0; i--) {\n balance = balance + gas[i] - cost[i];\n\n if(cost[i] < 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": "class Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n\n int totalgas = 0;\n int totalcost = 0;\n vector<int> diff(gas.size());\n\n for(int i = 0; i < gas.size(); i++){\n diff[i] = gas[i] - cost[i];\n }\n\n for(int...
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> res(gas.size(), 0);\n for (int i = 0; i < gas.size(); i++) {\n res[i] = gas[i] - cost[i];\n }\n int sum = 0;\n for (int i = 0; i < res.size(); 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 int n = gas.size();\n vector<int> net(n,0);\n int total_sum=0;\n for(int i=0;i<n;i++){\n net[i] = gas[i] - cost[i];\n total_sum += net[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\n vector<int> gasAdditionAtThisStop(gas.size());\n for(int i = 0 ; i < gas.size(); i++){\n gasAdditionAtThisStop[i] = gas[i] - cost[i];\n }\n for(int i = 0 ; i < gas.size();...
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);\n int sum = 0;\n for (int i = 0; i < n; i++) {\n diff[i] = gas[i] - cost[i];\n sum = sum + diff[i];\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 int n = gas.size();\n vector<int> net(n,0);\n int total_sum=0;\n for(int i=0;i<n;i++){\n net[i] = gas[i] - cost[i];\n total_sum += net[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);\n int gas_sum=0;\n int cost_sum=0;\n for(int i=0;i<n;i++){\n\n \t//cout<<gas[i]<<\" \"<<cost[i]<<\" \"<<gas[i]-cost[i]<<endl;\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\n vector<int> v(n, 0);// l(n, 0), r(n, 0);\n int sum = 0;\n for(int i = 0; i < n; i++){\n v[i] = gas[i] - cost[i]; // -9 6 3 3 -3 -2 -2 -2 3 3\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(n);\n for(int i=0; i<n; i++){\n arr[i] = gas[i]-cost[i];\n }\n int sum1 = accumulate(gas.begin(),gas.end(),0), sum2 = accumulate(...
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 int n;\npublic:\n // Start from station start and end at station stop, with a tank of size tank_initial \n void traverse(vector<int> &gas, vector<int> &cost, int tank_initial, int start, int stop, int &last_station, int &gas_needed_to_continue)\n {\n int tank = tank_in...
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 int n;\npublic:\n // Start from station start and end at station stop, with a tank of size tank_initial \n void traverse(vector<int> &gas, vector<int> &cost, int tank_initial, int start, int stop, int &last_station, int &gas_needed_to_continue)\n {\n int tank = tank_in...
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": "\nclass Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n\n // avaiable \n int available = 0;\n // deficient \n int deficient =0;\n // start kaha se kara jaha se possible nhi ho paya\n deque<int>q;\n\n for(int i=0;i<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": "\nclass Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n\n // avaiable \n int available = 0;\n // deficient \n int deficient =0;\n // start kaha se kara jaha se possible nhi ho paya\n deque<int>q;\n\n for(int i=0;i<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 net = 0;\n int i,n = gas.size();\n for(i=0;i<n;i++){\n net = net + gas[i] - cost[i];\n }\n if(net<0) return -1;\n i = 0;\n deque<int> D;\n in...
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": "\nclass Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n\n // avaiable \n int available = 0;\n // deficient \n int deficient =0;\n // start kaha se kara jaha se possible nhi ho paya\n deque<int>q;\n\n for(int i=0;i<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 allCost = 0;\n int allGas =0;\n for(auto i : cost){\n allCost += i;\n }\n for(auto i : gas){\n allGas += i;\n }\n if(allGas < allCost){\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 count=0;\n int currSum = 0, reqSum = 0, pos = -1;\n for(int i = 0; i < gas.size(); i++) {\n currSum += cost[i];\n reqSum += gas[i]; \n }\n if(reqSum <...
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 gsum = 0;\n for (auto a : gas) {\n gsum += a;\n }\n int csum = 0;\n for (auto a : cost) {\n csum += a;\n }\n if (csum > gsum) {\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 count=0;\n int currSum = 0, reqSum = 0, pos = -1;\n for(int i = 0; i < gas.size(); i++) {\n currSum += cost[i];\n reqSum += gas[i]; \n }\n if(reqSum <...
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 currSum = 0, reqSum = 0, pos = -1;\n for(int i = 0; i < gas.size(); i++) {\n currSum += cost[i];\n reqSum += gas[i]; \n }\n if(reqSum < currSum) return -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": "#include <vector>\nusing std::vector;\n\nclass Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size();\n vector<int> differences(n);\n std::transform(gas.begin(), gas.end(), cost.begin(), differences.begin(), std::minus<int>());\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": "#include <vector>\nusing std::vector;\n\nclass Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n int n = gas.size();\n vector<int> differences(n);\n std::transform(gas.begin(), gas.end(), cost.begin(), differences.begin(), std::minus<int>());\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": "\nclass Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n\n // avaiable \n int available = 0;\n // deficient \n int deficient =0;\n // start kaha se kara jaha se possible nhi ho paya\n vector<int>q;\n\n for(int i=0;i<ga...
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": "\nclass Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n\n // avaiable \n int available = 0;\n // deficient \n int deficient =0;\n // start kaha se kara jaha se possible nhi ho paya\n vector<int>q;\n\n for(int i=0;i<ga...
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 ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n \n vector<int> net_gas(gas.size()), sum_gas(gas.size());\n for(int i = 0 ; i < gas.size(); 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(std::vector<int> &gas, std::vector<int> &cost) {\n std::deque<int> q;\n q.push_back(0);\n while(q.size() <= gas.size()) {\n int start = q.back();\n int tank = 0;\n int offset = 0;\n while ...