Lecture 131: Buy and Sell Stock [Part 2] || DP Series

preview_player
Показать описание
In this Video, we are going to learn about Dynamic Programming. This Video marks the start of India's Biggest DP Series.

There is a lot to learn, Keep in mind “ Mnn bhot karega k chor yrr apne se nahi hoga ya maza nahi aara, Just ask 1 question “ Why I started ? “

Questions Links:

Do provide you feedback in the comments, we are going to make it best collectively.

Connect with me here:

Telegram Group Link: Love Babbar CODE HELP

Intro Sequence: We have bought all the required Licenses of the Audio, Video & Animation used.

#DP_Series #LoveBabbar
Рекомендации по теме
Комментарии
Автор

Well this question can also be solved without DP in Time O(N) and Space O(1)

"Intuition" : make a graph of all the price and pick all the lines which go upward

class Solution {
public:
int maxProfit(vector<int>& prices) {
int ans = 0;
for(int i=0;i<prices.size()-1;i++)
{
if(prices[i]<prices[i+1])
ans += prices[i+1]-prices[i];
}
return ans;
}
};

jayantasudhani
Автор

I can not explain how much I trust you bhaiya, you are really an great inspiration for me 👌👌👌👌

shriyanshkesharwani
Автор

Shuru majburi me kiye the....Pr ab mja aa rha hai...🔥

govindsuryavanshi
Автор

mazaa aaya ++
samajh aaya ++
Love You bhaiya 🙏

ajaybind
Автор

dp series is one who can never be made like this except far your contribustion love u

HIMANSHUSINGH-lioi
Автор

Greedy approach
class Solution {
public:
int maxProfit(vector<int>& prices) {
int profit=0;
for(int i=1;i<prices.size();i++){
if(prices[i]>prices[i-1])
}
return profit;
}
};
time complexity --> o(n)
Space complexity --> O(1)
Basically what is happening here is we are comparing every two values and adding all the maximas we are adding all the positive profits, hope it helps more
And thanks to bhaiya for this amazing course, learning a lot everyday

sarthaksingh
Автор

bhai logic smjhne k baad code to khud se hi kr logic chhaiye hota hai pura ka pura code khud hi kr leta babbar bhiya

adityarajvermaa
Автор

wao..U explained every thing so well..I have no word to say how smoothly u let us understand all complex concept..Thank you so much for your hard word for us!!

gitanjalikumari
Автор

sir, Please keep making these type of videos and complete this course . My Carrier is depend upon you
now.

appleinc.
Автор

really Grateful to Babbar bhaiya for free lectures 🙌

jatinranjan
Автор

Dp series . comming with good understanding of concepts..This is good to complete DP series.. Thanks

sukhjitsingh
Автор

Space optimization was really good. Nice video

JJFIREE
Автор

smjh aagya bhaiya !!! babbar bhaiya se acha koi nahi. I am spreading the word in my college .

anishawadh
Автор

swad++

pehle saare code as biggest as possible time complexity me karta tha par ab khud se hi optimize kar leta hu
thaks bhaiya ❤❤❤❤❤❤❤❤✌✌✌✌✌✌

aapne meri life++ kar di hai
thank you so much 😁😁

play_with_Vpp
Автор

Great vid. I'm learning a lot from this series

inter
Автор

Aaj sponsors me Upstox ya Zerodha hone chahiye the lol!

Sm
Автор

class Solution {
public:
int maxProfit(vector<int>& prices) {
int profit =0;
for(int i=1;i<prices.size();i++)
{
if(prices[i-1] < prices[i])
{
profit+=(prices[i] - prices[i-1]);
}
}
return profit;
}
};

trandingvideosong
Автор

aise bina DP k kar skte h
int maxProfit(vector<int>& prices) {

int l=prices[0], profit=0;
for(int i=1;i<prices.size();i++){
if(prices[i]<l)
l=prices[i];
if(prices[i]>l){
profit+=prices[i]-l;
l=prices[i];
}
}
return profit;
}

SiddharthDhiman
Автор

Maza aa gaya bhaiya
Consistantly follow your course
And keep it up bhaiya
After DSA make a full series on web development

mgfactors
Автор

aa gya bhaiya samajh, thank you so much

codingisfun-pranayharishch