id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n \n \n \n map<int,int>mapp;\n \n int so_far_maxx=0;\n \n int hey=0;\n \n for(int i=prices.size()-1;i>=0;i--)\n {\n int temp=so_far_maxx-prices[i];\n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& a) {\n int n=a.size();\n vector<vector<int>>dp(n,vector<int>(4,-1));\n return f(0,0,a,n,dp);\n }\n int f(int ind, int tra, vector<int>& a, int n, vector<vector<int>>& dp){\n if(ind==n || tra==4)return 0;\n if...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int solve(vector<int> &prices,int index,int transaction,vector<vector<int>> &dp){\n \n if(index==prices.size() || transaction==4) return 0;\n \n if(dp[index][transaction]!=-1) return dp[index][transaction];\n \n //profit 0 rakho-->\...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int f(int i, vector<int> &v, int buy, vector<vector<int>> &dp){\n if(i == v.size() or buy == 4) return 0;\n if(dp[i][buy] != -1) return dp[i][buy];\n if(buy % 2 == 0) return dp[i][buy] = max(-v[i] + f(i+1, v, buy+1, dp), f(i+1, v, buy, dp));\n retu...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int f(int i,int transactions,vector<int>&prices,vector<vector<int>>&dp){\n int n=prices.size();\n if(i==n || transactions==4){\n return 0;\n }\n if(dp[i][transactions]!=-1)return dp[i][transactions];\n int profit=0;\n if(tr...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n vector<int> nums=prices;\n vector<vector<int>> dp(nums.size()+1,vector<int>(5,0));\n\n for(int day=nums.size()-1;day>=0;day--){\n for(int trasaction=0;trasaction<4;trasaction++){\n int profi...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "int f(vector<int>,vector<vector<int>>&);\nint f(vector<int> arr,vector<vector<int>>&dp)\n{\n int m=dp.size()-2,n=dp[0].size()-2;\n for(int i=m;i>-1;i--)\n {\n for(int j=n;j>-1;j--)\n {\n if(j==0||j==2)\n {\n dp[i][j]=max(dp[i+1][j...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n\n int f(int i,int j,vector<int> &prices,vector<int> &mp,vector<vector<int>> &dp){\n int n=prices.size();\n if(i==n)return 0;\n if(dp[i][j]!=-1)return dp[i][j];\n if(j==1){\n return dp[i][j]=max(f(i+1,0,prices,mp,dp)-prices[i],f(i+1,1,pri...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int f(vector<int>& prices, int curr, int bought, int t_left, vector<vector<vector<long>>> &dp) {\n if (curr == prices.size()) return 0;\n\n if (dp[t_left][bought][curr] != -1) return dp[t_left][bought][curr];\n\n int a = 0;\n if (bought == 1) { \n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n memo = vector<vector<int>>(prices.size(), vector<int>(5, -1));\n return traverse(prices, 0, 0);\n }\n\nprivate:\n vector<vector<int>> memo;\n\n int traverse(vector<int>& prices, int index, int status) {\n if...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int solve(vector<int>&prices, int day, int transactionsLeft, vector<vector<int>>& Memo){\n if(day == prices.size())return 0;\n if(transactionsLeft == 0)return 0;\n \n int& ans = Memo[day][transactionsLeft];\n // cout<<ans<<endl;\n if ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int f(int i, int buy, vector<int>&prices, vector<vector<int>> &dp){\n if(i==prices.size()) return 0;\n if(buy==4) return 0;\n \n if(dp[i][buy]!=-1) return dp[i][buy];\n int l=0,r=0;\n if(buy%2==0){\n l = -prices[i]+f(i+1,bu...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int solve(int ind,int trans,vector<int>&prices,vector<vector<int>>&dp){\n if(ind==prices.size() || trans==4) return 0;\n if(dp[ind][trans]!=-1) return dp[ind][trans];\n int profit=0;\n if(trans%2==0) profit=max(-prices[ind]+solve(ind+1,trans+1,pric...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "#define ll long long \n#define REP(i,a,n) for(int i=a;i<n;i++)\nclass Solution {\npublic:\n int maxProfit(vector<int>& v) {\n ll n=v.size();\n vector<vector<ll>>dp(n,vector<ll>(5,0));\n // 1 means a stock is in hold \n dp[n-1][1]=v[n-1];\n dp[n-1][3]=v[n-1];\n f...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n // int f(int ind, int buy,int cap, vector<int>& p,vector<vector<vector<long long int>>> & dp){\n // if(ind==p.size() || cap==0) return 0 ;\n // long long int profit;\n // if(dp[ind][buy][cap]!=-1) return dp[ind][buy][cap];\n // if(buy){\n // ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n int currMin = prices[0];\n int currMax = 0;\n vector<vector<int>> dp(prices.size(), vector<int>(2, 0));\n dp[0][0] = 0;\n for (int i = 1; i < prices.size(); i++) {\n if (prices[i] < currMin)\...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n int currMin = prices[0];\n int currMax = 0;\n vector<vector<int>> dp(prices.size(), vector<int>(2, 0));\n dp[0][0] = 0;\n for (int i = 1; i < prices.size(); i++) {\n if (prices[i] < currMin)\...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n // long long max_profit(vector<int>& p, int i,int n, int cnt,vector<vector<int>>&dp){\n // if(i == n and cnt%2 == 0 and cnt <4){\n // return 0;\n // }\n // if(i == n and cnt%2 == 1 and cnt <4){\n // return INT_MIN;\n // }\n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n int maxP = 0;\n int size = prices.size();\n if (size == 0) return maxP;\n vector<vector<int>> hold(size + 1, vector<int>(3, 0));\n vector<vector<int>> unhold(size + 1, vector<int>(3, 0));\n hold[...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n int n_days = prices.size();\n vector<vector<int>> sell(n_days, vector<int>(2, INT_MIN/2));\n vector<vector<int>> hold(n_days, vector<int>(2, INT_MIN/2));\n\n for(int i = 0; i < n_days; i++) {\n if(!...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n\n int dp[1000005][10][2];\n int f(vector<int>& prices, int k ,int si , bool flag){\n \n if(si==prices.size()) return 0;\n\n if(dp[si][k][flag]!=-1) return dp[si][k][flag];\n int ans = INT_MIN;\n\n ans = f(prices,k,si+1,flag);\n\n i...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n int n = prices.size();\n vector<vector<int>> dp0(n, vector<int>(2,0));\n vector<vector<int>> dp1(n, vector<int>(2,0));\n vector<int> dp2(n,0);\n dp0[0][1] = -1*prices[0];\n dp1[0][1] = -1*prices[...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int dp[2][105][100005];\n int func(int buy, int k, int i, vector <int> &prices){\n if(k == 0) return 0;\n if(i == prices.size()) return 0;\n if(dp[buy][k][i] != -1) return dp[buy][k][i];\n if(buy){\n int op1 = -1*prices[i] + func(0,k,...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int dp[100005][105][2]; \n int BestTime(int idx, int k, vector<int> &prices, int buy) {\n int n = prices.size();\n if (idx == n || k == 0) return 0;\n \n if (dp[idx][k][buy] != -1) return dp[idx][k][buy];\n\n int ans = 0;\n if (buy) {\n int skip = B...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int dp[100005][105][2] ;\n int f( vector<int>& prices , int i , int k , bool on){\n if(i >= prices.size()) return 0 ;\n if(dp[i][k][on] != -1) return dp[i][k][on] ;\n int ans = INT_MIN ;\n ans = max(ans , f(prices , i+1 , k , on)) ;\n if(...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int dp[100005][105][2];\n int f(vector<int>&prices , int i,int k,bool on){\n if(i==prices.size()) return 0;\n if(dp[i][k][on]!=-1) return dp[i][k][on];\n int ans = INT_MIN;\n ans = f(prices,i+1,k,on);\n if(on){\n ans = max(ans,...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "\n\nclass Solution {\npublic:\n int arr[100005][105][2]; \n \n \n Solution() {\n fill(&arr[0][0][0], &arr[0][0][0] + sizeof(arr) / sizeof(int), -1);\n }\n\n int profit(std::vector<int>& prices, int i, int k, bool flag) {\n \n if (i >= prices.size() || k == 0) return 0;\...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& p) {\n vector<vector<int>> buy(p.size(),vector<int>(2,-1));\n vector<vector<int>> sell(p.size(),vector<int>(2,-1));\n return mem(0,p,0,0,buy,sell);\n // return rec(-1,p,0,0);\n }\n int mem(int f,vector<int>& p,int i...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int rec(int i, int s, int n, vector<int>& prices,vector<vector<int>>& dp,vector<vector<int>>& done){\n if(s==4) return 0;\n if(i>=n){\n return 0;\n }\n\n if(done[i][s]) return dp[i][s];\n\n int ans = rec(i+1, s, n, prices, dp, don...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution1{\npublic:\n int solve(int k,int count ,vector<int>& prices){\n if(count==0)return 0;\n if(k>=prices.size()-1){\n return 0;\n }\n else{\n int ans=0;\n for(int i=k;i<prices.size();i++){\n for(int j=i+1;j<prices.siz...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n int n = prices.size();\n vector <int> max_left (n, 0);\n vector <int> max_right(n, 0);\n set <int> seen_left;\n seen_left.insert(prices[0]);\n set <int> seen_right;\n seen_right.insert(pri...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n // int dp[100001][2][3];\n // int solve(int ind, int buy, int k, vector<int> &a){\n // if(k==0)return 0;\n // if(ind == a.size())return 0;\n // if(dp[ind][buy][k]!=-1)return dp[ind][buy][k];\n\n // int nottake = solve(ind+1,buy,k,a);\n // ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int recur(int i, int buy, int cap, vector<int>& prices, int n, vector<vector<vector<int>>>& dp){\n if(i == n || cap == 0)return 0;\n\n if(dp[i][buy][cap] != -1)return dp[i][buy][cap];\n\n if(buy){\n dp[i][buy][cap] = max(-prices[i] + recur(i+1,...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n set<pair<int,int>> st;\n int n=prices.size();\n vector<int> pf(n+1,0), suf(n+1,0);\n for(int i=0;i<n;i++){\n if(!st.empty()){\n pf[i]=prices[i]-(*st.begin()).first;\n }\n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n ios_base::sync_with_stdio(0);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int n = prices.size();\n vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(2,vector<int>(2,-1)));\n dp[n][0][0]=0;\n...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "auto speedUP = [](){\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\nclass Solution {\npublic:\n //Recursive\n //Important thing to learn, When I passed limit++ or ++limit than the answer was coming \n //wrong but when I passed limit + 1 than the answer...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"avx2,bmi,bmi2,popcnt,lzcnt\")\n\nstatic const int FAST__ = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\n int solveTab(vector<int> &prices)\n {\n int n=prices.size();\n vector<vector<vector<int>>> dp(n+1,vector<vector<int>> (2,vector<int> (3,0)));\n\n for(int index=n-1;index>=0;index--)\n {\n for(int buy=0;buy<=1;buy++)\n {\n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int f(int ind,bool buy,int cap,vector<int>& prices,int n, vector<vector<vector<int>>> &dp){\n if(ind==n || cap==0) return 0;\n int profit=0;\n if(dp[ind][buy][cap]!=-1){\n return dp[ind][buy][cap];\n }\n if(buy){\n prof...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n int n = prices.size();\n vector<vector<vector<int>>> dp(\n n + 1, vector<vector<int>>(2, vector<int>(3, 0)));\n int profit = 0;\n\n // because we're taking ind+1 that's why start from n-1\n f...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n int n = prices.size();\n vector<vector<vector<int>>> t(n+1,vector<vector<int>>(2,vector<int>(3,0)));\n for(int i = n-1;i>=0;i--){\n for(int buy=0;buy<=1;buy++){\n for(int cap=1;cap<=2;cap++)...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n int f(int ind, int buy, int cap, int n, vector<int>&prices,vector<vector<vector<int>>>&dp){\n\n if(cap==0 || ind==n) return 0;\n if(dp[ind][buy][cap]!=-1) return dp[ind][buy][cap];\n\n int profit=0;\n if(buy){\n profit = max(-prices[ind] ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
1
{ "code": "class Solution {\npublic:\n // int f(int idx, int buy, int txn, vector<int>& prices, vector<vector<vector<int>>>&dp) {\n // //bcase\n\n // if(txn == 0 || idx == prices.size()) return 0;\n\n // if(dp[idx][buy][txn] != -1) return dp[idx][buy][txn];\n // if(buy)\n // ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
2
{ "code": "class Solution {\npublic:\n\n int dp[100001][2][2];\n\n int sol(int i, vector<int>& prices, int buy, int total){\n if(i == prices.size() || total == 2)return 0;\n if(dp[i][buy][total] != -1)return dp[i][buy][total];\n int profit = 0;\n\n if(buy)profit = max(-prices[i]+sol(...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
2
{ "code": "class Solution {\npublic:\n\n int dp[100001][2][2];\n\n int sol(int i, vector<int>& prices, int buy, int total){\n if(i == prices.size() || total == 2)return 0;\n if(dp[i][buy][total] != -1)return dp[i][buy][total];\n int profit = 0;\n\n if(buy)profit = max(-prices[i]+sol(...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
2
{ "code": "class Solution {\npublic:\n int dp (vector <int> &prices, int cnt, int i, bool hold, vector <vector <vector <int>>> &tmp)\n{\n int n = prices.size();\n int mult = 1, cnt2 = cnt;\n if (!hold) mult = -1;\n else cnt2 = cnt+1;\n if (i == n and !hold) return 0;\n else if (i == n and hold) r...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
2
{ "code": "class Solution {\npublic:\n int f(int i, bool buy, int transactions, vector<int>& prices, int n, vector<vector<vector<int>>>& dp){\n if(transactions > 2){\n return -1e8;\n }\n if(i==n){\n return 0;\n }\n int &ans = dp[i][buy][transactions];\n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
2
{ "code": "class Solution {\npublic:\n //Tabulation\n int f(int i, bool buy, int k, vector<int>& prices, int n, vector<vector<vector<int>>>& dp){\n if(k == 0 || i==n) return 0;\n \n int &ans = dp[i][buy][k];\n if(ans != -1) return ans;\n \n if(buy){\n return ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
2
{ "code": "class Solution {\npublic:\n int f(int i, bool buy, int k, vector<int>& prices, int n, vector<vector<vector<int>>>& dp){\n if(k < 0){\n return -1e8;\n }\n if(i==n){\n return 0;\n }\n int &ans = dp[i][buy][k];\n if(ans != -1) return ans;\n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
2
{ "code": "class Solution {\npublic:\n\n int maxProfit(vector<int>& prices) {\n\n int n=prices.size(),ans=INT_MIN; \n vector<vector<int>>prev(2,vector<int>(3,0)); \n\n for(int i=0; i<n; i++){\n prev[0][0]=0; \n prev[1][0]=0;\n }\n\n for(int k=1; k<3; k++){\n...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
2
{ "code": "class Solution {\npublic:\n int f(int index, int buy, int cap, vector<int> prices,\n vector<vector<vector<int>>>& dp) {\n if (index == prices.size())\n return 0;\n if (dp[index][buy][cap] != -1)\n return dp[index][buy][cap];\n if (buy) {\n i...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\nint maximumProfit(vector<int>& prices, vector<vector<vector<int>>>& dp, int i, int isBought, int count){\n if(i == prices.size()||count >=2) return 0;\n if(dp[i][isBought][count] != -1) return dp[i][isBought][count];\n\n int skip = maximumProfit(prices, dp, i...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\n\n int solve(vector<int>&prices,int in,int b,int n,int t,vector<vector<vector<int>>>&dp)\n {\n if(t<=0||in==n)\n {\n return 0;\n }\n\n if(dp[in][b][t]!=-1)\n {\n return dp[in][b][t];\n }\n\n \n in...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "#include<bits/stdc++.h>\nclass Solution {\npublic:\n int n;\n vector<int>v;\n vector<vector<vector<int>>>dp;\n int rec(int level, int taken, int transactions) {\n if (level == n || transactions == 2) {\n return 0;\n }\n if (dp[level][taken][transactions] != -1) {...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "#include<bits/stdc++.h>\nclass Solution {\npublic:\n int n;\n vector<int>v;\n vector<vector<vector<int>>>dp;\n int rec(int level, int taken, int transactions) {\n if (level == n || transactions == 2) {\n return 0;\n }\n if (dp[level][taken][transactions] != -1) {...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\n\n int maxProfit(vector<int>& prices) {\n int n = prices.size();\n vector<int> sell(n, 0), buy(n, 0);\n set<int> st, ts;\n st.insert(prices[0]);\n ts.insert(prices[n-1]);\n for(int i=1;i<n;i++) {\n sell[i] = prices[i] - (*st...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\n vector<vector<vector<int>>> dp;\n int profit(vector<int>& prices, int index, bool can_buy, int count){\n if(count == 4 || index == prices.size())\n return 0;\n if(dp[index][can_buy][count] != -1)\n return dp[index][can_buy][count];\n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\nprivate:\n int f(int i, int buy, int cap, int n, vector<int>& prices,\n vector<vector<vector<int>>>& dp) {\n if (i == n || cap == 0)\n return 0;\n if (dp[i][buy][cap] != -1)\n return dp[i][buy][cap];\n long profit = 0;\n if (bu...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\n int stocks(int i, int limit , int buy ,vector<int>& prices , vector<vector<vector<long>>>& dp){\n\n if(i == prices.size() || limit==0) return 0;\n if(dp[i][buy][limit] != -1) return dp[i][buy][limit];\n\n long profit = 0;\n \n if(buy == ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "#include \"bits/stdc++.h\"\nclass Solution {\npublic:\n \n int func(int index,int k,vector<int> &prices,bool flag,vector<vector<vector<int>>> &dp){\n if(k<=0) return 0;\n if(index<0){\n return 0;\n }\n if(dp[flag][index][k]!=-1) return dp[flag][index][k];\n if(flag){\n int take...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\n\n int solve(vector<int> &v, int i, int buy,vector<vector<vector<int>>> &dp,int limit)\n {\n if(i>=v.size()) return 0;\n if(limit==0) return 0;\n\n if(dp[i][buy][limit]!=-1) return dp[i][buy][limit];\n int profit = 0;\n \n if(buy)\n...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\nlong f(vector<int>&prices,int idx,int buy,vector<vector<vector<long>>>&dp,int cap){\n if(cap==0 ||idx==prices.size())return 0;\n if(dp[idx][buy][cap]!=-1)return dp[idx][buy][cap];\n long profit=0;\n if(buy){\n profit=max(-prices[idx]+f(prices,idx+1,0,dp,cap)...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\nint mp(vector<int> & price, int n,int b,int t,vector<vector<vector<int>>>&dp){\n if(t==4)return 0;\n if(n==price.size()){\n if(t==2||t==0)return 0;\n return -1e6;\n }\n if(dp[n][b][t]!=-1){\n return dp[n][b][t];\n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\n long long dfs(int i, int buy, int cap, vector<vector<vector<long long>>>& dp,\n vector<int>& prices) {\n if (i == prices.size())\n return 0;\n if (cap == 0)\n return 0;\n if (dp[i][buy][cap] != -1)\n retur...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "#define ll long long\n\nclass Solution {\npublic:\n vector<vector<vector<ll>>> dp;\n \n ll good(ll ind, ll f, const vector<int>& v, ll n, ll curr)\n {\n if (curr == 2 || ind == n) return 0;\n if (dp[ind][f][curr] != -1) return dp[ind][f][curr];\n \n ll profit = 0;\n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\n int f(int ind, int buy, int cap, vector<int> &prices, vector<vector<vector<long long>>> &dp){\n int n=prices.size();\n if(cap==0) return 0;\n if(ind==n) return 0;\n\n if(dp[ind][buy][cap]!=-1) return dp[ind][buy][cap];\n\n long long profit=0...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\n int findProfit(int i, int sell, int remaining, vector<int> &prices, vector<vector<vector<int>>> &dp){\n if(i == prices.size() || remaining == 0){\n return 0;\n }\n if(dp[i][sell][remaining] != INT_MIN){\n return dp[i][sell][remaining...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\nint y(vector<int>&prices,int i, int flag,vector<vector<int>>&dp){\n if(i>=prices.size()){\n return 0;\n }\n if(dp[i][flag]!=INT_MAX){\n return dp[i][flag];\n }\n if(flag==0){\n return dp[i][flag]=max(y(prices,i+1,1,dp)-prices[i],y(prices,i+1,0,...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\nint y(vector<int>&prices,int i, int flag,vector<vector<int>>&dp){\n if(i>=prices.size()){\n return 0;\n }\n if(dp[i][flag]!=INT_MAX){\n return dp[i][flag];\n }\n if(flag==0){\n return dp[i][flag]=max(y(prices,i+1,1,dp)-prices[i],y(prices,i+1,0,...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\nint f(int index,int buy,int two,vector<int>& prices,vector<vector<vector<int>>>& dp)\n{\n if(index==prices.size() || two==0) return 0;\n \n if(dp[index][buy][two]!=-1)\n {\n return dp[index][buy][two];\n }\n if(buy)\n {\n int profit1=-prices[inde...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\n vector<vector<vector<int>>> dp;\n int solve(vector<int>& p,int i,bool canbuy,int k, vector<vector<vector<int>>>& dp)\n {\n int n=p.size();\n if(k==0 || i==n) return 0;\n if(dp[i][canbuy][k]!=-1) return dp[i][canbuy][k];\n if(canbuy)\n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n int n = prices.size();\n int K=2;\n \n vector<vector<vector<int>>> dp(K+1, vector<vector<int>>(n+1, vector<int>(2, 0)));\n\n for(int k=1;k<=K;k++)\n {\n dp[k][1][0] = -prices[0];\n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\n\n\nvector<vector<vector<int>>> dp;\nint rec(vector<int>& prices, int k, int idx , bool tobuy){\n\n if(idx==prices.size() || k==0){\n return 0;\n }\n\n if(dp[k][idx][tobuy] != -1){\n return dp[k][idx][tobuy];\n }\n\n if(tobuy){\n int a = - pric...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "class Solution {\npublic:\n\n int helper(int index, int buy, vector<int>& prices,\n vector<vector<vector<int>>>& dp, int count) {\n if(count==0)\n {\n return 0;\n }\n if (index == prices.size() - 1) {\n if (buy == 1) {\n return pr...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "static int __star = []{\n ios_base::sync_with_stdio(0);\n cin.tie(NULL),cout.tie(NULL);\n return 0;\n}();\nclass Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n int n = prices.size();\n int k =2;\n\n // Solve special cases\n if (n <= 0 || k <= 0) {\n ...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "static int __star = []{\n ios_base::sync_with_stdio(0);\n cin.tie(NULL),cout.tie(NULL);\n return 0;\n}();\nclass Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n ios_base::sync_with_stdio(0);\n int n = prices.size();\n int k =2;\n\n // Solve special cases...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "#pragma GCC optimize(\"Ofast\")\nstatic auto _ = [](){std::ios::sync_with_stdio(false); std::cin.tie(nullptr); return nullptr;}();\n\nclass Solution1 {\n std::vector<std::vector<std::vector<int>>> dp;\n int solve(int index, int curr, bool buy, std::vector<int> &prices, int n) {\n if(index == n...
123
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p> <p>Find the maximum profit you can achieve. You may complete <strong>at most two transactions</strong>.</p> <p><strong>Note:</strong> You may not engage in multiple tran...
3
{ "code": "#pragma GCC optimize(\"Ofast\")\nstatic auto _ = [](){std::ios::sync_with_stdio(false); std::cin.tie(nullptr); return nullptr;}();\n/*\nclass Solution1 {\n std::vector<std::vector<std::vector<int>>> dp;\n int solve(int index, int curr, bool buy, std::vector<int> &prices, int n) {\n if(index ==...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
0
{ "code": "#pragma GCC optimize(\"Ofast\")\nstatic auto _ = [](){ cin.tie(nullptr) -> ios_base::sync_with_stdio(false); return nullptr; }();\n#define endl \"\\n\"\n\nclass Solution {\npublic:\n int maxPathSum(TreeNode* root) {\n // find lowest node\n // go to parent node\n // -- check if left ...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
0
{ "code": "/**\r\n * Definition for a binary tree node.\r\n * struct TreeNode {\r\n * int val;\r\n * TreeNode *left;\r\n * TreeNode *right;\r\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\r\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\r\n * TreeNode(int x, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
1
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
124
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p> <p>The <strong>path sum</strong> of a pa...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...