DP 35. Best Time to Buy and Sell Stock | DP on Stocks 🔥

preview_player
Показать описание

Please watch the video at 1.25x for a better experience.

a

In this video, we solve the first problem on DP on Stocks. Its the Best time to buy and sell stocks.

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

Please give us a like and share this content as much as possible :)

takeUforward
Автор

8:36

The provided solution is not using dynamic programming. Dynamic programming involves breaking down a problem into smaller subproblems and solving each subproblem only once, storing their solutions to avoid redundant calculations.

The solution provided is a simple linear scan through the prices array, keeping track of the minimum price encountered so far (temp) and updating the maximum profit (maxi) accordingly. It doesn't involve breaking down the problem into subproblems or utilizing memorization of intermediate results, which are characteristic features of dynamic programming algorithms.

Instead, it employs a straightforward greedy approach to find the maximum profit by considering the difference between each price and the minimum price encountered so far.

avishkarpatil
Автор

Because of this guy, I love dynamic programming.

TW-ukxi
Автор

maan gye guru! this was my first video here and explnation was very good!

LowkeyCoder
Автор

I think u are the best teacher in this whole world...keep it up man...

RAKSHITHPGBBTCSBTechCSE
Автор

Hello, thanks for this solution. Lucid & perfectly explained. I have a simple doubt. How does this problem fall in the category of DP. I'm genuinely confused coz my understanding of DP is different. Pls Help.

rocktatnine
Автор

I think u are the best teacher in this whole world...keep it up man... I think u are the best teacher in this whole world...keep it up man... I think u are the best teacher in this whole world...keep it up man...🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰

samiranroyy
Автор

Thanks Striver, I have been stuck on the Buy and Sell stocks with at most k transactions problem for sometime now. Will wait for your video.

johncenakiwi
Автор

There are many ways of solving this problem, but your one is the best.!

shashankjagtap
Автор

Man, your DP playlist on YouTube will gonna rock 🥳

rahul-sinha
Автор

In java, Easy to understand

public static void main(String[] args) {
int arr [] = {7, 1, 5, 3, 6, 4};
int temp =0;
int max = Integer.MIN_VALUE;
for(int i=0;i<arr.length;i++) {
for(int j=i+1;j<arr.length;j++) {
temp = arr[j]-arr[i];
if(max<temp) {
max= temp;
}
}
}
if(max<=0) {
max=0;
}
System.out.println(max);

}

RogithRog
Автор

Bhai main DSA wala banda hun nhi, I'm a pure developer and I hate DSA due to its toughness but randomly today I thought of watching a video of Striver and I'm amazed. I'm able to understand it very well.
Hats off to you Striver for your explanation. Live a quality life bro ❤

AnandKumar-ogbu
Автор

video start krne se phle hi solve kr liya tha ....aut by chance same method nikla 😁😁....thanku striver

raghavmanish
Автор

Understood. Thanks a lot. Please upload more videos Bhaiyaaa

samuelfrank
Автор

understood. Please make a playlist for Greedy too. Thank You.

bhupendrasinghshahi
Автор

I was waiting for "whenever your heart is broken" and it never came XD

saketpatel
Автор

This was the one of the toughest question on dp string we came across specially with the base case, and omitting the for loop in Reccurence equation.
Thank you so much Striver Bhaiya you have made DP so intuitive like how to think from scratch
Thanks you so much again 💗

iEntertainmentFunShorts
Автор

best DP series ever....thanks Striver 💛

rishav
Автор

On the A2Z course u have this ques under arrays so how are we supposed to do it without dp?

rohanmadiratta
Автор

#Free Education For All.. # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India..

shubhamagarwal