DP 35. Best Time to Buy and Sell Stock | DP on Stocks 🔥
ฝัง
- เผยแพร่เมื่อ 14 มี.ค. 2022
- Lecture Notes/C++/Java Codes: takeuforward.org/dynamic-prog...
Problem Link: bit.ly/3rN7GIL
Please watch the video at 1.25x for a better experience.
Pre-req for this Series: • Re 1. Introduction to ...
a
Make sure to join our telegram group for discussions: linktr.ee/takeUforward
Full Playlist: • Striver's Dynamic Prog...
In this video, we solve the first problem on DP on Stocks. Its the Best time to buy and sell stocks.
If you have not yet checked our SDE sheet, you should definitely do it: takeuforward.org/interviews/s...
You can also get in touch with me at my social handles: linktr.ee/takeUforward
Please give us a like and share this content as much as possible :)
Thank you bro for your hard work to add new videos. Congratulations for completing 2 years on youtube :)
When will remaining DP problems will come ?
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.
true.. it greedy works best for this question
but Isn't it dividing into sub-problems as well if we carefully observe
The for loop at the time of the ith iteration will answer up to that ith iteration.
But you are correct in the sense that we are not leveraging this answer to find the next answer, however, we are leveraging minimum value to find the next answer
Yes, I agree with you
Because of this guy, I love dynamic programming.
Yes u will until u start solving different questions
@@rahulbhagat4023 so these questions are not enough?
@@rahulbhagat4023 Everyone starts somewhere ig. Many people found these problems ridiculously hard earlier
Codeforces me dp tag lagake 1800 rating laga..
Sara bhukar utar jayega :}
BTW no harm to striver bhaiya... He is explaining all the classical problems using which we can solve hard problems with sufficient practice.
Watching this whole play list is not at all sufficient. (Hard work from your end is needed)
@@nanda_8 yha 1500 nhi hore h bhai tu 1800 ki baat kr ra hai
I think u are the best teacher in this whole world...keep it up man...
maan gye guru! this was my first video here and explnation was very good!
UNDERSTOOD.....Thank You So Much for this wonderful video.....🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
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.
Following your entire DSA A2Z Course!
Understood. Thanks a lot. Please upload more videos Bhaiyaaa
Understood. Thankyou Sir
There are many ways of solving this problem, but your one is the best.!
Thank You!
Understood
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 ❤
I want to know how did you become a pure developer without DSA?
@@yashrajdeshmukh6759 U just need to know basics of DSA , OOPs Thats it .
good stuff buddy
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.
Understood Sir!
Understood✅🔥🔥
Understood ❤
Man, your DP playlist on TH-cam will gonna rock Man....!!!!! 🥳
Understood 💗
UNDERSTOOD!
Thank you bro. Understood
Ur really a saver of my life bhayya
Understood! thanks !! Long live !!!
Mast understood !!!!!!
Understood!!🙇♂
Awesome Sir..................
understood , thanks
understood. Please make a playlist for Greedy too. Thank You.
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 💗
Understood!
Understood !! :)
understood sir !
'
badiya
understood everything
Thank you so much for making such amazing content🙌❤
understood💙
Understood.
Understood !!
best DP series ever....thanks Striver 💛
understood ❤
Striver, you had been mentioning space optimization since a lot of videos on this playlist. But isnt it that it takes some amount of time to store the previous variables/vectors for previous rows into a temp vector? This would add up to the computation time right??? And in this era we care more of time reduction than space reduction. Kindly let me know if I am wrong, and if not, then why do we need space optimization? Thank you for your valuable time.
When using things on cloud, cost is charged effectively on both storage and number of operations/compute power used. Thats why maybe on a larger picture it's effective.
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
Wondering, if you should include this in DP playlist
4th November 2023, I'm watching this video while seeing Arrays Topic. Commenting here to see how long it takes for me to reach the same video in DP Playlist.
are you there yet buddy?
understood
Understood:)
Understood
I was waiting for "whenever your heart is broken" and it never came XD
Understood boss\/
In first iteration cost will be -6 so it will update it in cost or not ?
Then in max profit it will update it by -6 or not?
Or in mini while going i=2 how it will update min?
By the way Engineering means optimisation
so we have to optimise things
magician
never knew that we called this also as dynamic programming 😅
On the A2Z course u have this ques under arrays so how are we supposed to do it without dp?
I have a doubt. If there is an array of unknown values then how to find out the min value?
Sir can you please cover Linked List like Array series.Within a month ??
Why the lecturers never teach like this during college🙁
how would be able to solve it using recurrence. I'm unable to figure it out
I did this same question with dp without knowing I was doing dp 😅.
same with me bro . with same time complexity O(N) and O(1)
Bhaiya I m starting today DSA sheet I will mark in comments which day I m seeing your video like day 5 video I will comment in your video day 5completed it help me to make consistent thanks bhaiya
Understood DP Striver Sir
SDE Sheet Day 1 Problem 6 Done!
❤❤
We also apply that first find min from array then from that index to end find the maximum element,
please reply @take U Forward
Yeah even I got the same idea
fails for this case 2 7 1 2. answer is 5 (7-2).
can anyone explain for me why the space complexity is O(1) like he said?
Amazing explaination :)
My mind OHHHHH!
Can u please provide solution for tiling with dominoes. I have searched whole TH-cam and web but there is no good explanation
bhaiya please make a set of questions so that we can easily solve leetcode contest questions
Can anyone please reply Will the sorting technique work here Will sort the entire array And by difference out between the starting and the last index and of course, the difference would be maximum and will return the difference???????????/
No, it will not work.As it will destroy the sequence.
@@tbcreations2033 okay sir thanks so much for replying
question link given in the desc. box is wrong
When doing the problem without knowing that it's dp feels so easy.
US striver
Bhai i am also a working professional but I wanted to ask itna sab daily kaise karte ho ? office ka kaam phir video recording ya live stream ? burnout nahi feel karte kya ? I am on kinda similar grind of upskilling ... giving contest learning new tech stacks but kabhi kabhi social life ki L lag jate hai ...
Understood. Thank you so much
was waiting for this one......
The problem link in description is leading to some other problem.
Let m get that corrected
Damn well understood!!
understood.!!!!!!!!!!!!!!!
US
man you are amazing
how are you able to think like this
Hello.. Why is it price[i] - mini?????
How is Dynamic Programming ?
plzz make a video on maths required for competitive programming
what is the white board drawing app you are using?
Sir, there was no song in the end of this video :(
Understood :)
Done myself earlier itself
Aug'1,2023 10:10am
Why u didn’t do it with recursive dp?
"understood".
Part -1 Beautiful.
Time loss.... How we'll be assume which day it'll be 1 and which day it'll be 6
Thanks striver ❣️
brilliantly explained
Understood !!!
Can anybody tell me why we have to keep track of minimum cost too
to buy it at the lowest cost
Understood kaka!
21
Ye shi tha guru!
yes