DP 3. Frog Jump | Dynamic Programming | Learn to write 1D DP

  Рет қаралды 545,444

take U forward

take U forward

Күн бұрын

Пікірлер: 2 100
@takeUforward
@takeUforward 2 жыл бұрын
I need your support, and you can do that by giving me a like, and commenting "understood" if I was able to explain you.
@ManishKumar-ui1tf
@ManishKumar-ui1tf 2 жыл бұрын
Please Upload the next One video
@dhrubajyoti3774
@dhrubajyoti3774 2 жыл бұрын
Understood 🥺🥺
@somyadebsarkar6593
@somyadebsarkar6593 2 жыл бұрын
Can't we start from 0 and using recursion ?
@shubhamjha5738
@shubhamjha5738 2 жыл бұрын
koi compiler theek krao yrr python vla coding ninjas ka
@vishalkumarshaw9208
@vishalkumarshaw9208 2 жыл бұрын
We are with u.
@KaushalDhruw
@KaushalDhruw 5 ай бұрын
2 years later. Still the ultimate and unbeatable learning resource in the market.
@salmanpandey8150
@salmanpandey8150 3 ай бұрын
But i thought adita verma was best for dp
@riyasinghal2671
@riyasinghal2671 Ай бұрын
​@@salmanpandey8150yrr usne to mujko kisi pe bhi recursion karna bata diya bina soche uska base case nikap deta hun
@sanketdas7000
@sanketdas7000 2 жыл бұрын
The dp series is like web series. Every day a new episod is coming with lots of new things and leaving a suspence for the next one.. thank you striver for this wonderful effort..and "UNDERSTOOD"..
@skiver9763
@skiver9763 2 жыл бұрын
only if we could get a trailer for the next day's video😂
@jayantmishra6897
@jayantmishra6897 Жыл бұрын
this is the only playlist on youtube where you will find only positive comments because this man really put his effort to make this playlist valuable. thank you so much striver.
@manikantadevadiga7146
@manikantadevadiga7146 Жыл бұрын
i can see 2, striver and love babbar
@jeet-smokey
@jeet-smokey 3 ай бұрын
@@manikantadevadiga7146 Love Babbar copies from striver. I have seen many videos taking the same sample code and examples from striver.
@nitpBlogs
@nitpBlogs 2 ай бұрын
@@manikantadevadiga7146 Aditya Verma ka bhi dekh lo.
@haseebshaik8669
@haseebshaik8669 20 күн бұрын
After searching all over the world to grasp these DSA concepts, it wasn't until I watched this video that everything finally clicked. The way you explained it was beyond exceptional-thank you for creating such a clear and impactful resource!
@adarshanku7988
@adarshanku7988 2 жыл бұрын
This series is so damn good that before watching this video, i thought of giving "min cost climbing stairs" question on leetcode a try because i felt i could do that. That is similar to this question only. And boom, i solved that question in all possible ways...recursion, memoization, tabulation and space optimised method. Thank you striver. You have kinda opened our brain and made our thinking broader. Thank you so much for the inspiration you are. Love you !!!
@parthsalat
@parthsalat 2 жыл бұрын
Recursion code at 24:33 Memoization code at 25:25 Tabulation code at 30:54 Space optimization at 36:22
@prateeksaini8553
@prateeksaini8553 2 жыл бұрын
Thanks dude
@yournemesis8232
@yournemesis8232 2 жыл бұрын
Would recommend to watch completely without skipping though The insights given by him are great
@parthsalat
@parthsalat 2 жыл бұрын
@@yournemesis8232 Yes, you are right. This is just for jumping to the desired explanation without wasting time - when you are revising
@026harshagarwal9
@026harshagarwal9 2 жыл бұрын
We will take a for loop running from j=1 to k and instead of writing (ind-1) and (ind-2) we will going to simply write (ind-j) that will give me the solution. Time Complexity:-O(N*K) Space complexity:-O(N). Yes sir, it cannot be space optimised because we have to use K+1 variables . Nice video and yes you are absolutely right, I have learnt space optimisation in dp from you THANKS MAN 👍👍
@cipherCrafters14
@cipherCrafters14 2 жыл бұрын
baniya buddhi mat chalao jyada striver bhai ko appreciate kaaro khud toh kuch kar nahi raahe
@Anonymous-lw4nq
@Anonymous-lw4nq Жыл бұрын
@@cipherCrafters14 XD
@SayanKarmakar
@SayanKarmakar Ай бұрын
Learnt the concept, went straight to the editor, coded it in JAVA and submitted it...All test cases submitted 🔥👍 Striver's way of explaining recursion and DP is unbeatable and uncomparable
@sumitsanu9524
@sumitsanu9524 Жыл бұрын
You will get hired even if you can explain an interviewer till memoization thing but it will blow the mind of interviewer if you go till space optimisation to constant.... awesome video and striver is just god.
@balajiaadi1901
@balajiaadi1901 2 жыл бұрын
I recently started this dp series and i want to complete this series in 20 days this is my day 1 Thank you for this awesome series
@niyammuliya5787
@niyammuliya5787 2 жыл бұрын
follow ups solution: #include int frogJump(int n, vector &heights, int k){ vector dp(n, INT_MAX); dp[0] = 0; for(int i=1; i
@letslearn1055
@letslearn1055 Жыл бұрын
this is what i thought in the very first second.
@kanishyathra
@kanishyathra Жыл бұрын
@@letslearn1055 me too
@user-id7pz9bs2f
@user-id7pz9bs2f 10 ай бұрын
@@letslearn1055 same here when he said k jumps then i thought of a nested for loop till k
@uditgarg6508
@uditgarg6508 5 ай бұрын
mee too
@SuperSaber9
@SuperSaber9 2 жыл бұрын
Amazing video! Do watch till the end because in the space optimization part, the actual value of watching the past two videos comes.
@manideep7148
@manideep7148 4 күн бұрын
I did not see this series feeling that DP is soo tough but after listening to your explanation, I've changed my mind. All credits to you Striver !
@Harmless_creature
@Harmless_creature 7 күн бұрын
00:03 Find the minimum total energy used by the frog to reach the first stair 02:13 The minimum energy required to jump from one point to another is 20. 06:11 Recursion is a way to find the path with minimum energy. 08:30 The costing for this guy will be zero no matter what you do. 12:51 Applying memoization to optimize recursion 14:47 Return the minimum of the left and right subpoints 18:51 Recursion helps solve multiple sub problems by reusing previously solved solutions. 20:50 Convert a recursion solution to dynamic programming 24:48 Memoization and tabulation are two approaches to solve problems recursively and iteratively respectively. 26:43 The first step in tabulation is to initialize the dp array. 30:55 The space complexity can be optimized by using the index minus 1 and index minus 2 technique 32:49 Use variables instead of an array to store previous values. 36:49 The problem requires k jumps as a follow-up to i plus 1 and i plus 2. 38:38 The ultimate resource for placements
@PujaKumari-zl7rw
@PujaKumari-zl7rw 2 жыл бұрын
Understood, Honestly this is the very first time I am trying to learn any dp problem. And I am able to understand everything... Very clear explanation. Loved it.. Thanks a lot for all the efforts :)
@taukirlalwala2865
@taukirlalwala2865 2 жыл бұрын
Hey Striver! I tried solving this question myself and I was able to solve it, I must say this series is amazing. You started building my concepts in first 2 lectures itself. Gonna see your lecture now and look at your approach. Would surely complete whole dp series. Thank you for this series ❤
@firefly_3141
@firefly_3141 Жыл бұрын
Code Of Frog Jump #include using namespace std; //Top-Down Approach int dp1(int ind,vector&heights,vector&dp) { if(ind == 0) return 0; if(dp[ind] != -1) return dp[ind]; int left = dp1(ind-1,heights,dp) + abs(heights[ind]-heights[ind-1]); int right = INT_MAX; if(ind > 1) right = dp1(ind-2,heights,dp) + abs(heights[ind]-heights[ind-2]); return dp[ind] = min(left,right); } //Tabulation Method - Bottom Up Approach /* vectordp(n,0); dp[0]=0; for(int i=1;i 1) secondstep = dp[i-2] + abs(heights[i] - heights[i-2]); dp[i] = min(firststep,secondstep); } return dp[n-1]; */ //Space Optimization /* int prev=0; int prev2=0; for(int i=1;i1) secondstep = prev2+abs(heights[i]-heights[i-2]); int curi = min(firststep,secondstep); prev2 = prev; prev = curi; } return prev; */ int frogJump(int n, vector &heights) { vectordp(n+1,-1); return dp1(n-1,heights,dp); }
@adebisisheriff159
@adebisisheriff159 8 ай бұрын
Thanks so much Striver. We really appreciate your effort. You are a rare gem.
@studynewthings1727
@studynewthings1727 11 ай бұрын
The code for k jumps: #Memoization def k_jumps(n,dp,arr,k,result): if n == 0: return 0 if dp[n] != -1: return dp[n] for i in range(1,k+1): if (n > (i - 1)): step = k_jumps(n-i,dp,arr,k,result) + abs(arr[n] - arr[n-i]) else: step = 9999999 result = min(result,step) dp[n] = result return dp[n] arr = [30,10,60,10,60,50] n = len(arr) k = 3 result = 999999 dp = [-1 for i in range(n)] print(k_jumps(n-1,dp,arr,k,result)) #Tabulation def k_jumps(n,arr,k): dp = [-1 for i in range(n)] if n == 0: return 0 dp[0] = 0 for index in range(1,n): result = 999999 for i in range(1,k+1): if (index > (i - 1)): step = dp[index-i] + abs(arr[index] - arr[index-i]) else: step = 9999999 result = min(result,step) dp[index] = result print(dp) return dp[n-1] arr = [60,30,10,60,10,60,50] n = len(arr) k = 3 result = 999999 print(k_jumps(n,arr,k))
@ankitadas5833
@ankitadas5833 2 жыл бұрын
Amazing video! Everything is clearly understandable. from day 1 of dp series I have watching your videos and Day by Day become big fan of your teaching way. God bless you sir. Came to know from your insta story that u have fever 🤒 Get well soon sir.
@pjagannadham2540
@pjagannadham2540 2 жыл бұрын
Yes his teaching is absolutely marvelous and I become big fan of him he keep rocking now I am happy to be cse student 😇😇
@alisharath161
@alisharath161 10 ай бұрын
Best video I have ever seen on DP. Thank you Striver for helping out fellow developers.
@popularedits6984
@popularedits6984 2 жыл бұрын
UNDERSTOOD , Now I am loving dp its become easy to think from recursion to tabulation step by step, thank you so much for the hardwork!
@vibhorbhatt3076
@vibhorbhatt3076 11 күн бұрын
This question became a piece of cake for the one's following previous vedios. Thankyou Striver Bhaiya.
@ryanmathew6397
@ryanmathew6397 10 ай бұрын
your explanation is so good that even before you write the pseudo code, i was able to write the recursion by starting from 0 to n-1 rather than the reverse approach that you have taken in the video. Great Work you are doing. Helps to improve the way a person can solve a problem.
@tanishkumar6682
@tanishkumar6682 Жыл бұрын
Hey, striver i just want to say that concept in your videos are such a crystal clear and easy to understand that even i am studying for the first time i do not feel any difficulty to understand the solutions. so, thank you so much for providing such a video lecture free on youtube
@arghyadeepbhowmick2248
@arghyadeepbhowmick2248 Жыл бұрын
Understood!! After seeing the recursion, I was able to convert it on my own into a dp. Thank you STRIVER. ❤
@xlr8tanmay
@xlr8tanmay 2 ай бұрын
You need to learn Recursion bro
@pranavkutty5736
@pranavkutty5736 2 жыл бұрын
Understood! Your series is making me love DP. Thanks a ton! Excited for the next one.
@ragnos6756
@ragnos6756 Жыл бұрын
Approach: Since the frog can make k jumps, we can use k recursive calls and find the minimum of them. used a variable ans to kept it as positive infinity to update the answer . base case is same as the frog jumps qn. but since frog can make k jumps, used a for loop to find the the answer for every jump (1st , 2nd ,.... till kth). also a check of i-w>=0 is made so that there is no infinite recursion. def frogJump(n,heights,k) -> int: i=n-1 ans=float('inf') def helper(i,ans): if i==0: return 0 for w in range(1,k+1): if i-w>=0: find=helper(i-w,ans)+abs(heights[i-w]-heights[i]) ans=min(find,ans) return ans return helper(i,ans) def frogjump_tabulation(n,heights,k): dp=[0]*(n+1) dp[0]=0 for i in range(1,n): ans=float('inf') for j in range(1,k+1): if i-j>=0: find=dp[i-j]+abs(heights[i-j]-heights[i]) ans=min(ans,find) dp[i]=ans return dp[n-1]
@dEviL_bIsWaJiT
@dEviL_bIsWaJiT Ай бұрын
Understood, Thanks a lot bhaiya ❤
@gmh14
@gmh14 Жыл бұрын
At 25:23, can't you initialize the dp array for only n elements instead of n+1? Like you did for tabulation?
@nikhilprasad644
@nikhilprasad644 2 жыл бұрын
"UNDERSTOOD"..... Bhaiya pls upload practice problem link other than coding ninja link. Leetcode interface is best for easy understanding. I hope you understand , Thanks
@krishnachaitanya1265
@krishnachaitanya1265 2 жыл бұрын
Its not there on leetcode(Same problem)
@krishnachaitanya1265
@krishnachaitanya1265 2 жыл бұрын
Sadly leetcode is missing these kind of problems. No platform can match leetcode interface
@zaidshaikh2536
@zaidshaikh2536 2 жыл бұрын
A similar problem on Leetcode is Min cost Climbing stairs 746
@nikhilprasad644
@nikhilprasad644 2 жыл бұрын
@@zaidshaikh2536 bro i didnt ask for a similar problem on leetcode, I asked Striver bro to give the leetcode link and not the coding ninja link.
@simple_saviour4496
@simple_saviour4496 2 жыл бұрын
If possible pls provide leetcode problem link also of the particular problem since most of us are following leetcode
@zaidshaikh2536
@zaidshaikh2536 2 жыл бұрын
Similar problem on Leetcode is 746
@Cartooz0111
@Cartooz0111 Ай бұрын
this is the only playlist on youtube where you will find only positive comments because this man really put his effort to make this playlist valuable. thank you so much striver. ❤❤From Gujarat !! Jordar (Gujarati)!
@ArjunSehgal-gv1cc
@ArjunSehgal-gv1cc 6 ай бұрын
semester 1 is about to start,and i am on this lecture,super confident>3000
@albatrossgeez6637
@albatrossgeez6637 6 ай бұрын
bhai itna jaldi
@gajjalaharsha
@gajjalaharsha 2 жыл бұрын
Can we write base case for n=1, then can write Math.abs(heights[1]-heights[0])?
@takeUforward
@takeUforward 2 жыл бұрын
Yes
@Vishal-joshi1998
@Vishal-joshi1998 2 жыл бұрын
Count all possible palindrome in string with rearranging characters - Infosys 🙄
@SumitChauhan-vv5ix
@SumitChauhan-vv5ix 6 ай бұрын
This can be solve using combinatrix also , right??😅
@anukritigarg3039
@anukritigarg3039 Ай бұрын
Understood!! I was always scared of Dynamic Programming but you made it so easy 🔥
@vibhavsharma2724
@vibhavsharma2724 4 ай бұрын
understood this very well. Thanks to striver
@harshithaharshitha7927
@harshithaharshitha7927 20 күн бұрын
your intention is to make education easier...yes!! striver you did it....We learn from you.We will make you proud a Day...thankyou striver for this wonderful series..this is first comment on my youtube..try to ping my comment if u have time ❤
@parvathivanapilli8572
@parvathivanapilli8572 6 ай бұрын
Understood, Now I'm loving Dp Thank you Striver ❤
@satwiksrivastava
@satwiksrivastava Ай бұрын
I managed to do the space optimization on my own! That's just how good your explanation is!
@rohan8758
@rohan8758 4 ай бұрын
understood. Thanks for DP web series with addiction
@athangkulkarni8245
@athangkulkarni8245 8 ай бұрын
Understood! Also, I could do tabulation and space optimization on my own after watching the explanation! A very big Thank you🥺
@stith_pragya
@stith_pragya 8 ай бұрын
UNDERSTOOD...........😎😎😎😎😎😎
@joyassroybarua5861
@joyassroybarua5861 Ай бұрын
Thank you vai. Its really awesome. And love from Bangladesh
@user-xx4mc1ve5l
@user-xx4mc1ve5l 8 ай бұрын
Take the base case of index == 1 as return abs(heights[1]-heights[0]), makes the code a bit simpler without if else conditions.
@user-xx4mc1ve5l
@user-xx4mc1ve5l 8 ай бұрын
index == 0 condition stays as it is so basically two base cases
@monisavaratharaj
@monisavaratharaj Ай бұрын
US striver! TUF always takes us forward...No one can beat striver in explaining the problem
@stith_pragya
@stith_pragya 8 ай бұрын
Thank You Much for this wonderful video.............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@chandolumanishbabu6807
@chandolumanishbabu6807 Жыл бұрын
Frog jump with k jumps: #include using namespace std; int min_dp(int n, vector &heights, int ind, vector &dp,int k) { if (ind == 0) return dp[0]=0; if (ind == 1) return dp[1] = abs(heights[ind] - heights[ind - 1]); if (dp[ind] == -1) { vector temp(k); for(int i=1 ; i> n>>k; vector heights(n); for (int i = 0; i < n; i++) { cin >> heights[i]; } int ind = n-1; vector dp(n + 1, -1); cout> t; while (t--) { solve(); } return 0; }
@NirmalyaMusicOfficial
@NirmalyaMusicOfficial Ай бұрын
Understood each step in detail 💯
@AjaySingh-ty2wm
@AjaySingh-ty2wm 8 ай бұрын
JavaScript/ typescript all 4 ways // simple recursion function f(ind: number, heights: number[]): number { if (ind == heights.length - 1) return 0; let left = f(ind - 1, heights) + Math.abs(heights[ind] - heights[ind - 1]); let right = Infinity; if (ind > 1) right = f(ind - 2, heights) + Math.abs(heights[ind] - heights[ind - 2]); return Math.min(left, right); } // recusion with memoization function memoF(ind: number, heights: number[], dp: number[]): number { if (ind == heights.length - 1) return 0; if (dp[ind] != -1) return dp[ind]; let left = memoF(ind - 1, heights, dp) + Math.abs(heights[ind] - heights[ind - 1]); let right = Infinity; if (ind > 1) right = memoF(ind - 2, heights, dp) + Math.abs(heights[ind] - heights[ind - 2]); return dp[ind] = Math.min(left, right); } // tabulation function TabulationFrogJump(n: number, heights: number[]): number { let dp = new Array(n + 1).fill(0); dp[0] = 0; dp[1] = Math.abs(heights[1] - heights[0]); for (let i = 2; i 1) right = dp[i - 2] + Math.abs(heights[i] - heights[i - 2]); dp[i] = Math.min(left, right); } return dp[n]; } // space optimised tabulation function SpaceOptimisedTabulationFrogJump(n: number, heights: number[]): number { let prev1 = 0; let prev2 = Math.abs(heights[1] - heights[0]); for (let i = 2; i
@SoyaibZihad10
@SoyaibZihad10 8 ай бұрын
I am nothing but greatful. Wanna finish the whole playlist. Thanks a lot
@xlr8tanmay
@xlr8tanmay 2 ай бұрын
Amazing explanation. Perfect solution to explain in an interview..
@bhanderidhruvbhanderidhruv557
@bhanderidhruvbhanderidhruv557 4 ай бұрын
big thank you bhai for your hard work and make questions easy for us , again thank you with saying "we can't be lazy by seeing your high level of energy to teach us", "UNDERSTAND" 😍🥰🤩😇😘❤💘
@prabhakaran5542
@prabhakaran5542 7 ай бұрын
Understood ❤
@SethuIyer95
@SethuIyer95 5 ай бұрын
I am actually watching this to give a google interview sometime later but god damn, this is actually fun to learn lol
@studynewthings1727
@studynewthings1727 11 ай бұрын
time complexity and space complexity of memoization, 22:20
@keyurchaudhari94
@keyurchaudhari94 Жыл бұрын
K jumps code: int memomization(int index,vector &h) { vector dp(index+1,0); int fs=0;int ss=INT_MAX; for(int i=1;i=0) ss=dp[i-k-1]+abs(h[i-k-1]-h[i]); smallest=min(smallest,min(fs,ss)); dp[i]=smallest; } } } return dp[index-1]; }
@user-th4nl8rv7l
@user-th4nl8rv7l 3 ай бұрын
Bro the way u explained is just amazing
@mayank_singh_43
@mayank_singh_43 Жыл бұрын
I also started understanding dsa , you are magical man of programming world✌
@urdaddy8520
@urdaddy8520 11 ай бұрын
this space optimization technique is way too classic, thanks bhaiya
@ADITYASINGH-b4u
@ADITYASINGH-b4u Ай бұрын
understood every bit of content ...thank u for this amazing lecture
@lokeshreddy4148
@lokeshreddy4148 7 ай бұрын
I think it is the best solution to previous videos
@codewithom11
@codewithom11 Жыл бұрын
US😎 Before the lecture, i was having a lot of fear about tabulation. Bt now its totally clear.😇 Thanks Raj Bhaiyya
@harshrajhrj
@harshrajhrj Жыл бұрын
Very helpful and minute problems were explained nicely. Nothing best than this.
@thisismr900
@thisismr900 Жыл бұрын
Understood! hauuwa bana rakha tha dp ka 1 saal se man mein thanks 900
@jayujain2647
@jayujain2647 Жыл бұрын
Thanks a lot!!!! I was able to solve the video without seeing the video all because of you!!!!
@vanshbaghel5884
@vanshbaghel5884 Жыл бұрын
Regular Recursion using java: public static int frogJump(int n, int heights[]) { return dpRecursion(n - 1, heights); } private static int dpRecursion(int n, int[] heights) { if (n == 0) return 0; int left = dpRecursion(n - 1, heights) + Math.abs(heights[n] - heights[n - 1]); int right = n > 1 ? dpRecursion(n - 2, heights) + Math.abs(heights[n] - heights[n - 2]) : Integer.MAX_VALUE; return Math.min(left, right); }
@manasansh7198
@manasansh7198 11 ай бұрын
"UNDERSTOOD" Great series Striver
@user-to3jj8lj8h
@user-to3jj8lj8h Ай бұрын
Understood ! much appreciations to your efforts .
@abytespaceneeded
@abytespaceneeded 8 ай бұрын
Solution for Frog Jump: #include #include #include #include using namespace std; // recursion // Time Complexity: O(2^N) // Space Complexity: O(N) - stack space int helper(vector& nums, int index) { if(index == 0) return 0; int step1 = abs(nums[index] - nums[index-1]) + helper(nums, index-1); int step2 = INT_MAX; if(index - 2 >= 0) { step2 = abs(nums[index] - nums[index-2]) + helper(nums, index-2); } return min(step1, step2); } int forgJump(vector& nums) { int size = nums.size(); return helper(nums, size-1); } // memoization // Time Complexity: O(N) // Space Complexity: O(N) + O(N) - stack space int helper(vector& nums, int index, vector& dp) { if(index == 0) return 0; if(dp[index] != -1) return dp[index]; int step1 = abs(nums[index] - nums[index-1]) + helper(nums, index-1, dp); int step2 = INT_MAX; if(index - 2 >= 0) { step2 = abs(nums[index] - nums[index-2]) + helper(nums, index-2, dp); } return dp[index] = min(step1, step2); } int forgJump(vector& nums) { int size = nums.size(); vector dp(size, -1); return helper(nums, size-1, dp); } // Tabulation // Time Complexity: O(N) // Space Complexity: O(N) int forgJump(vector& nums) { int size = nums.size(); vector dp(size, 0); dp[0] = 0; for(int i=1;i= 0) { step2 = abs(nums[i] - nums[i-2]) + dp[i-2]; } dp[i] = min(step1, step2); } return dp[size-1]; } // Space Optimized // Time Complexity: O(N) // Space Complexity: O(1) int forgJump(vector& nums) { int size = nums.size(); int prev = 0, secondPrev = 0; for(int i=1;i= 0) { step2 = abs(nums[i] - nums[i-2]) + secondPrev; } int curr = min(step1, step2); secondPrev = prev; prev = curr; } return prev; }
@abhisheknemade2444
@abhisheknemade2444 8 ай бұрын
Thanks baiya very wonderfull video. I understood the video. Please make more and more videos. God will bless you. HK.
@umber3117
@umber3117 8 ай бұрын
Understood. Amazing explanation. Thanks a lot for making these videos.
@lifehustlers164
@lifehustlers164 5 ай бұрын
4/57 done!!! understood!
@ajayprajapati7914
@ajayprajapati7914 10 ай бұрын
Explanation is very high level❤❤❤
@LowkeyCoder
@LowkeyCoder 9 ай бұрын
"understood" i came here with a doubt that i am from java if i will be able to understand or not but what happened i understood as fine as i can and i can write the same in c++ with little bit of help oviously but thanks a lot !
@MrVishalSharmah
@MrVishalSharmah Ай бұрын
Code for K jumps : int f(int idx, int k, vector &heights, vector &dp) { if (idx == 0) { return 0; } if (dp[idx] != -1) { return dp[idx]; } int minCost = INT_MAX; for (int i = 1; i = 0) { int jumpCost = f(idx - i, k, heights, dp) + abs(heights[idx] - heights[idx - i]); minCost = min(minCost, jumpCost); } } return dp[idx] = minCost; } int frogJump(int n, int k, vector &heights) { vector dp(n + 1, -1); return f(n - 1, k, heights, dp); }
@user-bw7gb1yr1p
@user-bw7gb1yr1p 11 ай бұрын
yeah, Sir, I understood. your lecture is very informative..... thank you, sir.
@ashj1165
@ashj1165 8 күн бұрын
understood; possibly wont have to watch this topic again :)
@vikrammehra4354
@vikrammehra4354 3 ай бұрын
thanku striver bhaiya
@MDEMANURRAHAMAN-
@MDEMANURRAHAMAN- 4 ай бұрын
Best explanations indeed, love you man.
@sonukumarram1880
@sonukumarram1880 7 ай бұрын
US , such a cool explanation ... thnx for this wndrful playlist
@ashusnapx
@ashusnapx Жыл бұрын
#include int frogJump(int n, vector &heights) { if(n == 0) return n; int left = frogJump(n-1,heights) + abs(heights[n] - heights[n-1]); int right; if(n > 1) { right = frogJump(n-2,heights) + abs(heights[n] - heights[n-2]); } return min(left,right); } whats wrong?
@sankalpsamitkumarpatel429
@sankalpsamitkumarpatel429 Жыл бұрын
declare right = MAX_INT.
@dibyajyotinayak2235
@dibyajyotinayak2235 10 ай бұрын
Understood! Thanks for explaining beautifully!
@jaatharsh
@jaatharsh Жыл бұрын
awesome, loved the clear n cripsh explanation
@aasifali9139
@aasifali9139 Жыл бұрын
Thx for this video striver bhaiya. ***Understood***
@nagame859
@nagame859 Жыл бұрын
Understood! Just wow! Love DP ❤️
@G.Lakshmi_Prasanna
@G.Lakshmi_Prasanna Жыл бұрын
Clearly understood💯. Thank you so much for the series
@vijeshsshetty
@vijeshsshetty 2 ай бұрын
Understood. Great Playlist !!!!
@rajarshinath6194
@rajarshinath6194 10 ай бұрын
understood Sir... U are just GOD
@vm1662
@vm1662 Жыл бұрын
Understood!! Thanks a lot for creating this series.
@aagamjain2131
@aagamjain2131 Жыл бұрын
This playlist is worth the hype ❤‍🔥
@UECAshutoshKumar
@UECAshutoshKumar Жыл бұрын
Thank you sir Understood
@20arpitbhatnagarit7
@20arpitbhatnagarit7 Жыл бұрын
Instead of if clause sir you could have inserted the val of dp[1] and started loop from i = 2
@user-zm9qn2sp3h
@user-zm9qn2sp3h 11 ай бұрын
UNDERSTOOD. Your explanation is damn good bro. thanks alot.❤
@Happy-tf7se
@Happy-tf7se 4 ай бұрын
As I am declaring the dp array globally it is giving incorrect answer. What could be the reason?? vector dp(100000,INT_MAX); int solve(int ind, vector& height){ if(ind==0) return 0; if(dp[ind]!=INT_MAX) return dp[ind]; int jumpTwo = INT_MAX; int jumpOne= solve(ind-1, height)+ abs(height[ind]-height[ind-1]); if(ind>1) jumpTwo = solve(ind-2, height)+ abs(height[ind]-height[ind-2]); return dp[ind]=min(jumpOne, jumpTwo); } int frogJump(int n, vector &heights) { // Write your code here. return solve(n-1,heights); }
@beilulbilly2636
@beilulbilly2636 8 ай бұрын
Love the way you explained
@madhurbanger6874
@madhurbanger6874 21 күн бұрын
UNDERSTOOD!!!
@fanofabdevillersandmathslo5960
@fanofabdevillersandmathslo5960 25 күн бұрын
Understood
DP 4. Frog Jump with K Distance | Lecture 3 Follow Up Question
17:35
take U forward
Рет қаралды 287 М.
Incredible Dog Rescues Kittens from Bus - Inspiring Story #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 34 МЛН
女孩妒忌小丑女? #小丑#shorts
00:34
好人小丑
Рет қаралды 98 МЛН
Пройди игру и получи 5 чупа-чупсов (2024)
00:49
Екатерина Ковалева
Рет қаралды 4,7 МЛН
Fastest Way to Learn ANY Programming Language: 80-20 rule
8:24
Sahil & Sarra
Рет қаралды 840 М.
DP 2. Climbing Stairs | Learn How to Write 1D Recurrence Relations
13:17
Launching the best DSA Course + Platform
36:29
take U forward
Рет қаралды 208 М.
5 Simple Steps for Solving Dynamic Programming Problems
21:27
Reducible
Рет қаралды 1 МЛН
DP 6. House Robber 2 | 1D DP | DP on Subsequences
9:50
take U forward
Рет қаралды 290 М.
Incredible Dog Rescues Kittens from Bus - Inspiring Story #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 34 МЛН