I need your support, and you can do that by giving me a like, and commenting "understood" if I was able to explain you.
@ujjawal_
2 жыл бұрын
Very helpful series bhaiya
@shubhamtanwar679
2 жыл бұрын
US Bhaiya, Aapka padane ka trika bhut acha lagta h
@JitendraKumar-ti6yd
Жыл бұрын
@@shubhamtanwar679 bhai ye batao why they have returned 1e9, if apane Integer.MAX_VALUE return krte toh ans glat aa rha
@shubhamtanwar679
Жыл бұрын
@@JitendraKumar-ti6yd max_value k liye long use karna padega is liye integer value le lete h 1e9 means 10^9👍 next videos dekhte rho subset wali problems me ye doubt bataya h
@kholiyamails1257
Жыл бұрын
@@shubhamtanwar679 bhaiya link dedo idhar jis problm ki bast kre ho
@akshitsingh2598
Жыл бұрын
In The memoization Approach please don't take INT_MAX in the base condition for (i
@stite1191
11 ай бұрын
thanks
@akshitsingh2598
11 ай бұрын
@@stite1191 don't mention
@parthparmar9798
11 ай бұрын
But instead of modifying the base case, you can modify the final return statement to return min(up,left)+ a[i][j]
@apputadhiyal9451
8 ай бұрын
@@parthparmar9798 yeah i also did the same thing
@HimanshuKumar-hp1vj
7 ай бұрын
int up = (i > 0) ? arr[i][j] + helper(arr, dp, i - 1, j) : INT_MAX; int left = (j > 0) ? arr[i][j] + helper(arr, dp, i, j - 1) : INT_MAX; i did like this
@keertilata20
2 жыл бұрын
The entire process recursion -> memoization -> tabulation -> space optimization is running on my mind all day. I love DP now and all thanks to you :) You are the BEST!!
@aniketchourasia7261
2 жыл бұрын
:)
@pratyushagrawal3464
Жыл бұрын
Same Here, Its like I have unknowingly memorized it ❤
@fmkhandwala39
2 жыл бұрын
have not watched pass 2:41, just saw the problem, went ahead and tried to solve it on my own. 1) figured recurrsion 2) did memoization 3) did tabulation 4) and even did space optimization Striver bhai if you need any proof, if whether or not your teachings help students or not, here is this. I used to skip the problems whenever it had DP in tags. Not anymore. Thank you very much!
@takeUforward
2 жыл бұрын
Just spread this series, this is what I will expect :)
@hyperme1831
2 жыл бұрын
Hey can you please tell me why in unique grid path we have initializing everytime up=0 left=0 inside 2nd loop before calling up and left . And why not in this minimum path sum in grid
@aarzookhunger9487
8 ай бұрын
@@hyperme1831 This is too late but.. if you're trying to draw similar lines between this and prev ques doing it this way may help you int right=1e8 , down=1e8; // so that while finding the min our ans doesn't get affected , if we instead initialise to zero here our actual dp[i][j] value will go wrong if(i>0) right = grid[i][j] + dp[i-1][j] ; if(j>0) down = grid[i][j] + dp[i][j-1];
@sridhanush6969
2 ай бұрын
@@hyperme1831 it may be a late reply but the reason is that we need to find the minimum path. if we initilize i = 0 and j = 0. if the left path is invalid ie.. if i
@dhyanprasad5611
Жыл бұрын
Striver , after watching 7-8 lectures of dp series , before the next vodeo starts , i try and solve the question on my own from what I've learnt and your teaching method is so versatile that every time i get 'all test cases passed' on leetcode, I'm filled with joy. #STRIVEROP #DPOP
@ompriya442
Жыл бұрын
instead of returning INT_MAX i think the best option is to apply conditions at up and left calls say for up if(M>=1) and for left if(N>=1) it will remove the other base case and also don't forget to initialise the up and left with INT_MAX value
@shivangisrivastava1158
2 жыл бұрын
Understood so well with your prev lectures that i could solve this ques by myself for damn all 4 methods! like i am blown! I am totally new to DP and this man is a gem!.
@AquaRegia-i3u
Жыл бұрын
💡Quick Tip : Instead of adding grid[i][j] while finding minimum, you can first find minimum of dp[i-1][j], dp[i][j-1] and then add grid[i][j]. Because if you get INT_MAX from recursion and then you add grid[i][j] it will become negative and effect the answer.
@Anonymous_Coder
Жыл бұрын
Great , i was also thinking over this , if we are returning INT_MAX in negative index base case , It is giving me some unexpected answers but if I am giving 1e9 , it is working fine. Got the problem now ..!
@RupamSasmalYt
Жыл бұрын
You have taught the DP. 8 lecture so well that I've solved the 9th and 10th qs by my own without seeing your solution.. DIl se Thank you ♥
@nilimsankarbora5911
9 ай бұрын
You have taught the last two lectures so well that i have solved this problem in all the three ways by myself ! And when i was able to do that i could not beilieve myself that i did it! You are an awsome teacher !
@pranavbhalerao308
2 жыл бұрын
*Understood* I also have to say I did this problem with 0(1) space complexity all by my own all thanx to the way you optimize it at the end I got an idea of not just how to solve it via recursion and then convert it to dp, but also optimized the space. Ik I am late by few months but won't go without completing the full playlist.
@mradulchourasiya3868
Жыл бұрын
O(1) ? But how max I can do is O(m) even with space optimization.
@sushant_hegde
Жыл бұрын
@@mradulchourasiya3868 No new trick. Just modify the original matrix itself to store the DP values. But as it modifies the original, not recommended. #include int minSumPath(vector &grid) { int m=grid.size(), n=grid[0].size(); for(int j=1;j
@pranavbhalerao308
Ай бұрын
@@mradulchourasiya3868 U change the matrix values itself instead of assigning new matrix or anything
@ayushpatel-ib3yj
Жыл бұрын
Striver , after watching 7-8 lectures of dp series , before the next vodeo starts , i try and solve the question on my own from what I've learnt and your teaching method is so versatile that every time i get 'all test cases passed' on leetcode, I'm filled with joy
@adarshanku7988
2 жыл бұрын
Even though solving before the question before watching the video, i still watch the whole lecture. And everytime i feel i have learnt something new. You have done amazing sir. 😍
@tasneemayham974
Жыл бұрын
Striver I tried to solve this alone, and I did!! I am soo happy you are my first mentor to teach me DP. Instead of returning MAX value if(i
@HimanshuSingh-zu4ht
2 жыл бұрын
understood very well please upload videos daily on regular time we know its hard for you but if possible please consider this.
@navpan18
2 ай бұрын
Can't express in words how much you helped me
@aniruddhsingh5280
Жыл бұрын
understood !! Getting better at Dp day by day 😁
@udatyadeb101
Жыл бұрын
I have understood but because of the last two lectures, I was able to solve this problem in all the three ways all by myself. Gaining some confidence now...
@trojanhorse8278
Жыл бұрын
I think we can use dijkstra's algo with some modification. It will work fine imo. Though im not sure about how optimal it will be but it can find the answer for sure.
@sneekpeek639
Жыл бұрын
Yes i was thinking the same
@parthdurgude2617
Ай бұрын
striver, I solved this Q in 10-15 mins on my own, though I forgot to include the grid[0][0] thats why took 5 mins more of debugging, Thankyou!!! I am getting more and more confident in DP with every Q I solve.
@dharmeshpoladiya9047
2 жыл бұрын
Understood 💯💯 Great Explanation. Thank you very much for all you efforts🔥🔥
@prasannasippa5962
Жыл бұрын
after watching these dp videos, now solving dp problems is solving two sum problem. really easy in one go its accepted each step running in my mind thank you so much striver.
@garvitrajput8491
2 жыл бұрын
qoute by striver maheswari - "Today's decision might effect you tomorrow"😂 , jokes apart very good series on DP
@parthsalat
2 жыл бұрын
Underrated comment
@devsharma181
6 ай бұрын
Happy to solve this question before seeing the video...i even had different base cases (like u went from bottom to top but i did in opposite order) thanks striver
@ankitadas5833
2 жыл бұрын
understood sir !!! I Think at 01:30,matrix final index should be (1,2). And You gave the Ninja Training's problem link not minimum path sum In Grid
@achrafBadiry
Жыл бұрын
Your videos have been the most useful in dynamic programming so far. I finally understand and I can go to the interview with a smile on my face. Thank you
@PANKAJKUMAR-oy1hh
2 жыл бұрын
in space optimize solution, one array(length m) and one variable would be enough to solve it. we could avoid taking two arrays.
@dipanshusharma9084
2 жыл бұрын
how ?
@kv5204
2 жыл бұрын
i dont think that approach will work, you will be needing to save the current row in an array for when we move to the next row. Single variable wont work.
@aniketchaudhary5803
2 жыл бұрын
@@kv5204 actually it is possible int n = grid.size(); int m = grid[0].size(); vector prev_row(m, 0); for(int i = 0; i < n; i++) { int curr_row = 0; for(int j = 0; j < m; j++) { if(i == 0 && j == 0) curr_row = prev_row[j] = grid[i][j]; else{ int up = 1e9, left = 1e9; if(i > 0) up = grid[i][j] + prev_row[j]; if(j > 0) left = grid[i][j] + curr_row; curr_row = prev_row[j] = min(up, left); } } } return prev_row[m-1];
@aniketchaudhary5803
2 жыл бұрын
We can also solve this problem without using any array or any variable, in O(1) space complexity. int n = grid.size(); int m = grid[0].size(); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(i == 0 && j == 0) continue; else{ if(i == 0 && j > 0) grid[i][j] += grid[i][j-1]; else if(j == 0 && i > 0) grid[i][j] += grid[i-1][j]; else grid[i][j] += min(grid[i][j-1], grid[i-1][j]); } } } return grid[n-1][m-1];
@ranitdey5829
Жыл бұрын
dude I have been going through your DP series. You have literally explained the most difficult topic in interviews on which I've struggled for years in a way that I won't ever forget. Thanks man! ❤
@champion5946
2 жыл бұрын
UnderStood anyone following the series properly can solve this question by himself
@vrandakansal5940
2 жыл бұрын
I can't believe that I have solve that problem by myself this is only possible because of u. You teach so so well... Thanks a ton!!
@amarkumar021
2 жыл бұрын
Thank you so much Striver for this playlist. Much appreciated!! I have a doubt While doing boundary check if we return Integer_MAX_VALUE to get this path eliminated then just by adding something to it, it goes into negative. This is the obvious, as we are adding each cell value. Rather if we take some random big number that is enough to clear all test cases but how can we be sure that path sum will always be smaller, There is very very less probability that it may fail. Is there any way to prevent this?
@saurabhraj201
2 жыл бұрын
I think instead of adding the returned value at line 4 and 5 directly.. We can first check min values among them and while returning it from the function we can do g[m][n] + max(left, right).. This way, we are not adding any extra value to left or right so it should work fine even if we take INT_MAX.
@no-body7286
2 жыл бұрын
you can return -1 and if you get -1 don't add it to your solution .
@sagarchawla4926
Жыл бұрын
Do check the constraints
@sagarchawla4926
Жыл бұрын
@@saurabhraj201 was looking for this, btw we had to take minimum not max
@biplawkumarsingh864
Жыл бұрын
@@sagarchawla4926 we can do this : int minPathSum(vector& grid) { int m = grid.size(); int n = grid[0].size(); vector dp(n, -1); for (int i = 0; i < m; i++) { vector temp(n); for (int j = 0; j < n; j++) { if(i==0 && j==0) temp[j] = grid[i][j]; else{ int up = INT_MAX, left = INT_MAX; if (i > 0) up = grid[i][j] + dp[j]; if (j > 0) left = grid[i][j] + temp[j - 1]; temp[j] = min(up, left); } } dp=temp; } return dp[n-1]; }
@ShivamKumar-kd1ww
2 жыл бұрын
I did the question in 2 minutes, without even looking at your solution. You teach very well.
@samirkumar9908
2 жыл бұрын
striver please try to complete it fast our Placements are near
@KCODivyanshuKatyan
2 жыл бұрын
I am able to the space optimisation myself which i thought was beyond my league such is the level of this guy's teaching.❤️🙌💕
@bhavanapateriya9966
2 жыл бұрын
Hello Striver - Can we also do all these grid question using dfs ?
@thinkingmad1685
2 жыл бұрын
The recursion is in a way dfs only
@pranavsharma7479
2 жыл бұрын
i guess yes
@jayantmishra6897
2 жыл бұрын
i am addicted to your lecture just because in every lecture i am learning something new.
@pryansh_
10 ай бұрын
its not enough that I succeed, others should fail too !
@divycodes
3 ай бұрын
yes, the graph solution using dijkstra's algorithm does work maintain the visited[][] array otherwise it will give TLE on larger test cases, visited[][] is required because if we have reached a certain coordinate with certain pathCost, then it is the minimum that is possible for this coordinate because of the priority queue, hence we should not be adding the same coordinate with another cost if encountered some time later as it will be of higher pathCost that the previous one, TC - O(m*n)*O(log(m*n)) SC - O(2*m*n) class Solution { class Info{ int x, y, pathCost; Info(int x, int y, int pathCost){ this.x = x; this.y = y; this.pathCost = pathCost; } } public int minPathSum(int[][] grid) { int m = grid.length, n = grid[0].length; if(m == 1 && n == 1) return grid[0][0]; int[][] visited = new int[m][n]; visited[0][0] = 1; PriorityQueue pq = new PriorityQueue((Info i1, Info i2)->Integer.compare(i1.pathCost, i2.pathCost)); pq.offer(new Info(0, 0, grid[0][0])); int[] dx = {0, 1}; int[] dy = {1, 0}; while(!pq.isEmpty()){ Info cell = pq.poll(); int x = cell.x; int y = cell.y; int pathCost = cell.pathCost; if(x == m - 1 && y == n - 1){ return pathCost; } for(int i = 0; i < 2; i++){ int newX = x + dx[i]; int newY = y + dy[i]; if(newX >= m || newY >= n) continue; if(visited[newX][newY] == 0){ pq.offer(new Info(newX, newY, pathCost + grid[newX][newY])); visited[newX][newY] = 1; } } } return -999; } }
@HarshitMaurya
2 жыл бұрын
i'm able to do this question in O(1) space , just modifying the input array : public int minPathSum(int[][] grid) { int m=grid.length,n=grid[0].length; for(int i=0; i0) grid[i][j]+=grid[i-1][j]; else { grid[i][j]+=Math.min(grid[i-1][j],grid[i][j-1]); } } } return grid[m-1][n-1]; } ThankU So Much Bhaiya ❤️
@manaskumarpanda3343
2 жыл бұрын
yes bro we can do this things in other previous code as well
@paracetamol9116
4 ай бұрын
never do this in an interview, you're not supposed to modify the input parameters
@TP-rs2un
Жыл бұрын
Thank you for this clear and thorough explanation. I finally start to understand DP.
@manikiran949
9 ай бұрын
thank you very much sir , For the first time I solved a dp problem by myself after watching your previous videos.
@sushant8686
2 жыл бұрын
done my myself thanks man love u
@deonarayanchoudhari5237
2 жыл бұрын
Just saw Unique Path and was able to solve this and last lecture's problem by myself, Thank You so so so so much for explaining with such clear logics. Understood and Thank You Striver.
@ishangujarathi10
Жыл бұрын
Understood!! even tried it myself after watching previous lectures!!!!
@ssv6055
2 жыл бұрын
Done ,was busy few days...but i am back !!
@marothee
6 ай бұрын
Heya Striver, I think for space optimization we can simply take one int[n] array, for up we can access array[j] and likewise update array[j]
@prabhaskoya
Жыл бұрын
dp[i-1][j]*(i>0) you can write like this
@ankitgupta8372
Жыл бұрын
Hey man, I was struggling a lot since last 2 years. Your videos are just awesome. I am gaining a lot of confidence in dp. Thanks to you!!!. God bless you
@harshittiwari1821
9 ай бұрын
By watching your lecture 8, I was able to solve both L9 and L10 problem. So really, Thank you.
@Morimove
9 ай бұрын
watched until 5:22 and did solved the question on my own. very happy. note: this comment is to remind me if I came to this question in my future.
@rishabhgupta9846
Жыл бұрын
Understood,thank you striver because of your teaching style I'm able to solve by myself
@MukeshKumar-cc3uh
8 ай бұрын
Playlist is just amazing. Thank you Striver. "Understood". ❤
@the-tech-jerry
9 ай бұрын
Excellent job man, really loved your work on DP and without doubt best so far on youtube. Keep it up 🔥🔥🔥
@aayush5474
2 жыл бұрын
You dont need to declare a dp array . You can operate on the existing matrix that is provided to you.This will reduce space complexity to O(1)
@takeUforward
2 жыл бұрын
When you operate on a given matrix, its considered as space in interview.
@aps8874
4 ай бұрын
Thank you so much! Did this on my own. Just came here to verify :)
@studyonline3236
Жыл бұрын
FYI - this can be done in-place by editing the matrix def f(m,n,grid): # inplace for i in range(1,m): grid[i][0]+=grid[i-1][0] for i in range(1,n): grid[0][i]+=grid[0][i-1] for i in range(1,m): for j in range(1,n): grid[i][j]+=min(grid[i-1][j],grid[i][j-1]) return grid[m-1][n-1]
@AshishKumar-ww1mr
Жыл бұрын
did this one only using previously taught concepts, awsome teaching bro. appreciate the efforts.
@himanshuagrawal8012
2 жыл бұрын
Now I can say...I LOVE DP 💕💕
@pradeeppradhi8792
11 ай бұрын
UNDERSTOOD and thank you so much for these lectures
@GopalKumar-py2cf
Жыл бұрын
now i feel confident in dp and solve question before watching the video thankyou for providing such a amazing lecture.
@shaik1525
8 ай бұрын
Understood bhaiayya... you are making dp easy for me.
@PriyankaDevi-vc8lb
2 жыл бұрын
It's very easy to understood when u watch grid path video
@JaspreetKaur-ku7pf
11 ай бұрын
bro you are so so good at teaching, i just can't express 🔥🔥🔥. Keep growing, our support is with you. And at last UNDERSTOOD
@nathamuni9435
Жыл бұрын
this booooooms my mind as it can solid take an hour and half or more
@anujrathore5726
3 ай бұрын
i did this que by myself , thank you striver
@davidmwangi4312
Жыл бұрын
BEST Dp Series to ever come across.
@TheK_Fam
7 ай бұрын
Understood, bro you are a GOAT teacher man!
@ganeshkamath89
2 жыл бұрын
Thanks Striver. Understood. I think for the first time I am able to solve DP problem.
@CodeMode9313
Жыл бұрын
previous videos were awesome so ye khud hogya ..thanks habibi
@sakshamsharma4713
2 жыл бұрын
Understood!! The best series for DP so far on youtube. You r the best Striver bhaiya providing such classy content at 0 fees. Thank u bhaiya for this amazing series..
@katamsreeja6744
2 жыл бұрын
Understood it clearly. Thank you so much.
@ranasauravsingh
2 жыл бұрын
UNDERSTOOD...! Thanks striver for the video... :)
@madhu_mohanreddy
Ай бұрын
for tabulation just intialize up = INT_MAX and left = INT_MAX
@varindersingh_
2 жыл бұрын
Understood. Thanks for creating the playlist.
@MrBlack-fj8ju
2 жыл бұрын
In the life of my cs youre the best teacher
@mankaransingh1029
2 жыл бұрын
Understood Waiting for the next lecture!!
@AyanAbbas-ps8xv
Ай бұрын
For those who might be getting error as "signed integer overflow" that is due to usage of INT_MAX . and if you add somthing like 4+INT_MAX then it gets into overflow error . so replace that INT_MAX with a different big integer like 9876543 etc.... Hope this helps.
@shriharshbankapur5232
2 жыл бұрын
Understood!! feeling better than when I started Checkpoint 1
@rahulchaudhary2441
2 жыл бұрын
Amazing charisma, "understood" from my side.
@abhigyan23111995
2 жыл бұрын
Understood. Superb Explanation.🔥
@cinime
2 жыл бұрын
Understood! I appreciate for your explanation!!
@coder0799
2 жыл бұрын
Wanna learn dp..just go too takeuforward dp playlist.. Thank you Bhaiya ❤️ for such a wonderful playlist..
@agamjotsingh4762
2 жыл бұрын
Understood. Crystal Clear
@rapido568
2 жыл бұрын
Understood and also gained more confidence. thank you striver❤❤
@abdalla4425
10 ай бұрын
Understood, 2d space optimzation was a little confusing but I'm getting the hang of it now!!
@sharayuyadav9511
3 күн бұрын
If you use input matrix to store the path sum, you don't need the prev and cur matrix, further space optimization I guess
@chidambarjoshi3470
Жыл бұрын
I think you did miss two base cases, i.e if(i==0) return dp[i][j] = left; and if(j==0) return dp[i][j] = up;
@tasneemayham974
Жыл бұрын
No there is no need for these base cases.
@UECAshutoshKumar
8 ай бұрын
Thank you sir 😁 Understood!
@aradhyapandey1489
10 ай бұрын
loving this series!!❤❤❤❤
@v.sreesairam9488
2 жыл бұрын
crystal clear explanation thank you bhaiya :)
@parthsalat
2 жыл бұрын
I bow down to the God striver, who taught me to solve DP questions on my own - from recursion till space optimisation. Hail Striver 🙏
@latenightstories1398
Ай бұрын
my concern is that when we are taking the example of why not greedy then we can apply greedy from the right bottom and it will give right answer
@ratinderpalsingh5909
2 жыл бұрын
Understood, sir. Thank you very much.
@kumarpurushottam632
Жыл бұрын
I Simply Loved It 😍. Thanks Striver🥰
@amansingh.h716
Ай бұрын
wow graph series helping here again did with dikastara BFS
Пікірлер: 1 М.