Please give us a like and share this content as much as possible :)
@lapimpale2 жыл бұрын
Thank you bro for your hard work to add new videos. Congratulations for completing 2 years on youtube :)
@rechinraj1112 жыл бұрын
When will remaining DP problems will come ?
@avishkarpatil58718 ай бұрын
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.
@_AmbujJaiswal5 ай бұрын
true.. it greedy works best for this question
@saatvikmangal79943 ай бұрын
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
@priyanshkumar173 ай бұрын
Yes, I agree with you
@muskan_bagrecha2 ай бұрын
Yep agreed. I was confused why this problem was tagged under DP.
@krishnagarg2583Ай бұрын
i have recursion function for this question i did u can use it for memoization and tabulation int maxProfitRec(vector& arr, int index, int minPrice, int maxProfit) { int n = arr.size(); // Base case: If we have processed all days, return the maximum profit found if (index == n) return maxProfit; // Update minimum price minPrice = min(minPrice, arr[index]); // Calculate profit if we sell on this day int currentProfit = arr[index] - minPrice; // Update the maximum profit maxProfit = max(maxProfit, currentProfit); // Recursive call for the next day return maxProfitRec(arr, index + 1, minPrice, maxProfit); } int maxProfit(vector& arr) { // Start with the first day's price as the initial minimum price and 0 as initial max profit return maxProfitRec(arr, 0, INT_MAX, 0); }
@rocktatnine Жыл бұрын
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.
@TW-uk1xi2 жыл бұрын
Because of this guy, I love dynamic programming.
@rahulbhagat40232 жыл бұрын
Yes u will until u start solving different questions
@ShubhamVerma-hw4uj2 жыл бұрын
@@rahulbhagat4023 so these questions are not enough?
@priyanshumohanty52612 жыл бұрын
@@rahulbhagat4023 Everyone starts somewhere ig. Many people found these problems ridiculously hard earlier
@nanda_82 жыл бұрын
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)
@ShubhamVerma-hw4uj2 жыл бұрын
@@nanda_8 yha 1500 nhi hore h bhai tu 1800 ki baat kr ra hai
@RAKSHITHPGBBTCSBTechCSE Жыл бұрын
I think u are the best teacher in this whole world...keep it up man...
@AyushSharma-s8tАй бұрын
haha, i think uu are new on youtube..
@johncenakiwi2 жыл бұрын
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.
@GaneshBhutekar-nu1gd9 күн бұрын
I was unable to figure out the best time to buy and sell stock in part 3. Later, I realized that there is a whole series on this topic. I had actually attempted part 1 of this series before, but I couldn't relate it to part 3.
@samiranroyy17002 ай бұрын
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...🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰
@stith_pragya9 ай бұрын
UNDERSTOOD.....Thank You So Much for this wonderful video.....🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@shashankjagtap5051 Жыл бұрын
There are many ways of solving this problem, but your one is the best.!
@AbhiRam-b2k Жыл бұрын
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.
@AnshKumar-tj8bn4 ай бұрын
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.
@jaishriharivishnu3 ай бұрын
some of the questions can't be solved without space optimization. let suppose you have n=100 and X=1e6... now if you make int dp[100][1e6] this will cost you 1e8 space... which is not possibe and will give you segmentation error... With "prev" and "cur" space optimization you can do it in 2*X space... i.e order of 6
@RogithRog5 ай бұрын
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
@akankshaawasthi3932 Жыл бұрын
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?
@shambhaviaggarwal997723 күн бұрын
Understood, thanks!
@rahul-sinha2 жыл бұрын
Man, your DP playlist on KZbin will gonna rock Man....!!!!! 🥳
@AnandKumar-og8bu Жыл бұрын
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 ❤
@yashrajdeshmukh6759 Жыл бұрын
I want to know how did you become a pure developer without DSA?
@iamnoob75939 ай бұрын
@@yashrajdeshmukh6759 U just need to know basics of DSA , OOPs Thats it .
@bhupendrasinghshahi59332 жыл бұрын
understood. Please make a playlist for Greedy too. Thank You.
@torishi823 ай бұрын
Nobody explains like you. Awesome.
@hashcodez7572 ай бұрын
"UNDERSTOOD BHAIYA!!"
@arkaprabhasaha82035 ай бұрын
Following your entire DSA A2Z Course!
@imtsrk0411 ай бұрын
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.
@AyushVerma-wu3nn7 ай бұрын
are you there yet buddy?
@raghavmanish242 ай бұрын
video start krne se phle hi solve kr liya tha ....aut by chance same method nikla 😁😁....thanku striver
@keshavbaheti732725 күн бұрын
Done, will never be coming back to see this video again. Note to self
@samuelfrank1369 Жыл бұрын
Understood. Thanks a lot. Please upload more videos Bhaiyaaa
@kaichang8186Ай бұрын
Thanks for the great effort
@Hrushi_2000 Жыл бұрын
Understood. Thankyou Sir
@ivoryAlpaca2 ай бұрын
Striver, you really are a legend
@iEntertainmentFunShorts2 жыл бұрын
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 💗
@prabhakaran55426 ай бұрын
Understood ❤
@shubhamagarwal14342 ай бұрын
#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..
@UECAshutoshKumar3 ай бұрын
Thank You! Understood
@KarthikNandam-xs4qn7 күн бұрын
Understood My G 🔥
@Mythri3332 күн бұрын
Thank you ❤
@ganeshjaggineni40972 ай бұрын
NICE SUPER EXCELLENT MOTIVATED
@anshulrai6058Ай бұрын
understood👍
@rishav1442 жыл бұрын
best DP series ever....thanks Striver 💛
@sanchitdeepsingh96634 ай бұрын
understood , thanks
@jaackiye3 ай бұрын
Understood! thanks !! Long live !!!
@konankikeerthi4 ай бұрын
Thank you bro. Understood
@ajitpal08212 жыл бұрын
We also apply that first find min from array then from that index to end find the maximum element, please reply @take U Forward
@hahahaha4217 Жыл бұрын
Yeah even I got the same idea
@AquaRegia-i3u Жыл бұрын
fails for this case 2 7 1 2. answer is 5 (7-2).
@gautamsaxena4647Ай бұрын
understood bhaiya
@arjunavsaikia62396 сағат бұрын
good
@heyOrca27117 ай бұрын
Understood Sir!
@reddevilbeast15 Жыл бұрын
Sir can you please cover Linked List like Array series.Within a month ??
@siyangaming32422 жыл бұрын
I don't know DP. but i solved this problem. from basic problem solving skills my aproach was: 1. find the minimum element in array. 2. then find the maximum element in the remaining array from the minimum number position. ex: suppose i found min element 2 at 3rd index then find the max element in the remaining array from 4th index to n; 3. subtract the maximum element - minimum element. BOOM ans is ready
@salilkumar94522 жыл бұрын
But this is wrong ex : 2,10,1,4
@sreenivasprasad65382 жыл бұрын
What if maximum element is at 0th index and minimum element is at last index. BOOM ans is wrong.
@umashankar123182 жыл бұрын
@@sreenivasprasad6538 😂
@swastikpatro6436 Жыл бұрын
😂😂😂
@anndiegeeky6217 Жыл бұрын
I also thought but this will be wrong when Array is 1000,2000,999,1002
@adityarao41572 ай бұрын
Its a simple greedy algo, dont blame him he is just making sure of getting the gist of the questions we ll encounter in this type of pattern
@armaanhadiq37412 жыл бұрын
By the way Engineering means optimisation so we have to optimise things
@wecan27296 күн бұрын
class Solution { public int maxProfit(int[] arr) { int mn=arr[0]; int n=arr.length; int ans=0; for(int i=1;i
@JatinGupta-ze6nc8 ай бұрын
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
@sahilsaini45746 ай бұрын
how would be able to solve it using recurrence. I'm unable to figure it out
@tester9920testerАй бұрын
please explain with tree backtraking this solution
@as_if3 ай бұрын
My approach was finding the next greatest selling cost, which required 2 loops. And the difference is here we're finding previous smallest buying cost, that is already in the memory. This dropped the time to O(n). We moved our search-for-information from the unexplored area to the already explored area.
@msannitya61445 ай бұрын
Ur really a saver of my life bhayya
@srinathv14129 ай бұрын
Mast understood !!!!!!
@oyeesharmeАй бұрын
thanks bhaiya
@resetengineering Жыл бұрын
Wondering, if you should include this in DP playlist
@gentleman7060 Жыл бұрын
Why u didn’t do it with recursive dp?
@AnkitSingh-wq2rk2 жыл бұрын
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 ...
@tvrao1237 ай бұрын
this solution is wrong for the test case, price = [100,180,260,310,40,535,695]
@suyashshinde2971 Жыл бұрын
SDE Sheet Day 1 Problem 6 Done!
@shouryadubey287818 күн бұрын
understood
@sarangkumarsingh79017 ай бұрын
Awesome Sir..................
@khalasianiket8164 ай бұрын
understood ❤
@Hipfire7866 ай бұрын
understood everything
@kartikeymishra56472 жыл бұрын
never knew that we called this also as dynamic programming 😅
@NonameNoname-f2t8 ай бұрын
understood sir ! '
@jaishriharivishnu3 ай бұрын
4:00 i will approach this with priority queue
@rohanmadiratta6421 Жыл бұрын
On the A2Z course u have this ques under arrays so how are we supposed to do it without dp?
@LazyCoder206 күн бұрын
@rohanmadiratta6421 . I know its late but If you are solving just with arrays knowledge it can be solved this way. " int maxPro = 0; int n = prices.length; for(int i=0;i
@rushyya Жыл бұрын
UNDERSTOOD!
@DeadPoolx17122 ай бұрын
UNDERSTOOD;
@itzzz4811 ай бұрын
Why the lecturers never teach like this during college🙁
@Rob-J-BJJ Жыл бұрын
good stuff buddy
@YourCodeVerse Жыл бұрын
Understood✅🔥🔥
@vigneshkumar49905 ай бұрын
understood💙
@damnrish4873Ай бұрын
Understood!!
@jaykumargupta73072 жыл бұрын
question link given in the desc. box is wrong
@chirag71269Ай бұрын
STRIVER 🔥
@saimasyeda654418 күн бұрын
Understood
@linhinNTU Жыл бұрын
can anyone explain for me why the space complexity is O(1) like he said?
@niladrisekharnath2 жыл бұрын
How is Dynamic Programming ?
@SmartStudyHub27 Жыл бұрын
I have a doubt. If there is an array of unknown values then how to find out the min value?
@rishabhgupta12226 ай бұрын
Understood DP Striver Sir
@chetanthakral53222 жыл бұрын
The problem link in description is leading to some other problem.
@takeUforward2 жыл бұрын
Let m get that corrected
@Shivi325904 ай бұрын
Understood!
@HARSHA_2711 ай бұрын
Understood!!🙇♂
@sumdeb19872 жыл бұрын
what is the white board drawing app you are using?
@SaifAliKhan-nm4em2 жыл бұрын
I did this same question with dp without knowing I was doing dp 😅.
@siyangaming32422 жыл бұрын
same with me bro . with same time complexity O(N) and O(1)
@iamnoob75939 ай бұрын
US striver
@asikakhatoon3091 Жыл бұрын
Time loss.... How we'll be assume which day it'll be 1 and which day it'll be 6
@shashankdaksh75542 жыл бұрын
Can u please provide solution for tiling with dominoes. I have searched whole KZbin and web but there is no good explanation
@rutikabhuimbar47342 жыл бұрын
Thank you so much for making such amazing content🙌❤
@thisguyispeculiar7 ай бұрын
Understood.
@HassanAbbas-wy7wjАй бұрын
goat striver💪
@fmkhandwala39 Жыл бұрын
understood
@thefourhourtalk4 ай бұрын
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???????????/
@tbcreations20334 ай бұрын
No, it will not work.As it will destroy the sequence.
@thefourhourtalk4 ай бұрын
@@tbcreations2033 okay sir thanks so much for replying
@itsme98778 ай бұрын
Hello.. Why is it price[i] - mini?????
@parthh3963Ай бұрын
in this question what if we need to print the days where we bought and where we sold the stock? can someone give me the solution to this?
@saketpatel81552 жыл бұрын
I was waiting for "whenever your heart is broken" and it never came XD
@kunalbandooni40092 жыл бұрын
Sir, there was no song in the end of this video :(