Explaining things like "Why won't Greedy work here", then going from "recursive" approach to optimized DP approach. This is how everyone wants to see a problem and this is how everyone should look at a problem. Start from worst and make improvements step by step. This makes your teaching style special. Thanks
I come here whenever I start to feel anxious about my solution not panning out, and I'm solving in Python. :) Thanks again for these walk-throughs, they really help. =D
Thanks for this approach! Using the greedy and recursive approaches helped me understand why one would use the DP method. Nothing else made sense up until now. Keep it up!
This is a best ever video I have ever seen from this only one video I clearly understand the GREEDY, RECURSION AND BACKTRACKING also hats off dude to your work
i did by marking technique (iterative) like if you have not encountered then add that state and mark it but if you have encountered that (check by using mark 2d array )state before then take minimum of previous and current state(bit mathematical) that also lead me to AC but thanks for this beautiful approach bro! today the base case could'nt stop us in the first go lol!!
That's incorrect at 7:18; memoization significantly improves time. For a 15x16 grid I was able to reduce recursive calls from 445,962,869 to 479 where there were 209 cache hits. The time dropped from 1347 ms to 1ms. That's a 1347 times improvement on time and nearly 100,000 times improvement on recursive calls. This was with Java using a 2D array for the cache (i.e. memoization) instead of HashMap. The time spent filling the array with -1's had little impact. Using HashMap also had good time of 7 ms with the same improved numbers for recursive calls and cache hits.
you help me a lot! I am a beginnner and this question is just too hard for me. After watching your video, i am able to finish a similar question by myself!
Dude! Your accent is tough, but after watching your video, I feel EXTREMELY comfortable applying minimum and maximum cost sum traversal algorithms through graphs!!
Great explanation !! The steps which we followed were the exact steps and approaches which came to my mind while looking at this problem for the very first time. I was able to go till recursion(backtracking) approach but could not figure out the last one. Thanks !! This was helpful.
Nice explanation sir....but instead of taking an additional dp vector if we do changes in the given grid vector only then it will be o(1) space solution
It's so easy to understand and I loved the break down from the simple to sophisticated approach! I have a question re the recursive solution - why is the complexity O(2^n) and not O(2^(m*n))? if it means that there's 2 options to about each cell..? Thank you
I am stuck with a similar problem which is finding shortest path in 2D matrix from source to target which given in the problem and I have to return all i,j coordinates of the shortest path only. Please help.
def findPath(x:int,y:int): if(x= len(grid) or y=len(grid[0])): return right = findPath(x,y+1) down = findPath(x+1,y) return min(right,down)+grid[x][y] I used this method. I know you said recursive method won't work but I tried for my satisfaction. But when compiling it gives error because it isn't able to compare right and left when the boundary check returns null. Can you tell me where am I wrong
TIME will be same either you do Top down or Bottom up because you will be doing same number of operations using the same algo and the same logic path. If you are getting confused then just rotate the matrix by 180 degrees them bottom up approach will become top down.
It will depend on no of repeating subproblems. Actually 2^N is a much larger upper bound due to the constraint in movement. But yes, memoization should give approx N^2. But since we are still doing recursion, actual runtime can go much higher than table method if you get large matrix. So, table method is best for larger cases. I hope you got it :)
Explaining things like "Why won't Greedy work here", then going from "recursive" approach to optimized DP approach. This is how everyone wants to see a problem and this is how everyone should look at a problem. Start from worst and make improvements step by step. This makes your teaching style special. Thanks
Welcome :)
i agree. this is one of the best videos.
That's makes sense
well said! I agree
Just in 14 mins
The best. I like the use of colors that made it easy to follow.
Thanks :)
I come here whenever I start to feel anxious about my solution not panning out, and I'm solving in Python. :) Thanks again for these walk-throughs, they really help. =D
Welcome :)
Clearest explanation of 3 different approaches to solving Minimum Path Sum problem 💯
I just had an assessment wish I saw this video earlier. The question was very similar. I appreciate your content thank you!
Thanks 😊
Explanation for Why greedy algorithm doesn't work was top notch. people usually doesn't try to think or explain in that angle. Thanks
Thanks for this approach! Using the greedy and recursive approaches helped me understand why one would use the DP method. Nothing else made sense up until now. Keep it up!
Thanks! Please keep going!!! Thanks soooooooooo much!!! I saw a lot of vedio about this question, you have the best explination.
The best video i found so far to explain this problem.
Thanks bro
Hats off to your teaching style! Legit the best explaination.
This is a best ever video I have ever seen from this only one video I clearly understand the GREEDY, RECURSION AND BACKTRACKING also hats off dude to your work
Thanks 😊
You are mastered in explaining the things man.
Such a neat explanation with clear voice and the colour combination will make us remember easy.
Great :)
You explain both problem and solutions very well. Commenting for expressing gratitude as well to offer support. Please keep up the good work.
memoization approach did work like a charm, instead of a 2D array, I have used unordered_map where key was a pair of i,j value.
It got accepted.
Share your code bro :)
Hey Piyush Share your code
Can you please share your code?
using map insted to 2-d arr wont work
@@Amitkumar-nw5mt It will definitely work
i did by marking technique (iterative) like if you have not encountered then add that state and mark it but if you have encountered that (check by using mark 2d array )state before then take minimum of previous and current state(bit mathematical) that also lead me to AC but thanks for this beautiful approach bro! today the base case could'nt stop us in the first go lol!!
This concept is same as memoization. Today I already wrote the base case 🤣
the way you explain complex things in easy way is awesome. please make more problems solution of leetcode .
Sure :)
As usual sir I was able to solve this within minutes with your explanation.
Another amazing explanation, I can't really thank you enough sir! I :) The bright colours in the video really helps a lot too
Thanks 😊
Literally best explaination on youtube
That's incorrect at 7:18; memoization significantly improves time. For a 15x16 grid I was able to reduce recursive calls from 445,962,869 to 479 where there were 209 cache hits. The time dropped from 1347 ms to 1ms. That's a 1347 times improvement on time and nearly 100,000 times improvement on recursive calls. This was with Java using a 2D array for the cache (i.e. memoization) instead of HashMap. The time spent filling the array with -1's had little impact. Using HashMap also had good time of 7 ms with the same improved numbers for recursive calls and cache hits.
you help me a lot! I am a beginnner and this question is just too hard for me. After watching your video, i am able to finish a similar question by myself!
Great :)
I hope this channel reaches 1m soon!
Thanks for your support 😀
LeetCode only has a bit over 200K users with a contest ranking, so that might take a while
Dude! Your accent is tough, but after watching your video, I feel EXTREMELY comfortable applying minimum and maximum cost sum traversal algorithms through graphs!!
Great :) Sorry for this accent though 😅
Thank you for the simple and elegant explanation!
Welcome :)
Wonderful Explanation BY Tech Dost.. (Dosh)
Great explanation !!
The steps which we followed were the exact steps and approaches which came to my mind while looking at this problem for the very first time.
I was able to go till recursion(backtracking) approach but could not figure out the last one.
Thanks !! This was helpful.
this explanation couldn't be better!! thanks
Welcome :)
Nicely explained the concept. Really like it. I was able to solve the similar problems in less time. Thanks a lot for the detailed explanation
The best explanation I have ever seen.
I am falling in love with your Explanation 💖
😀
Brilliant Explaintion techdose
Thanks
Nice video. Covered various approaches here.
Thanks
bhai op zeher explaination🔥🔥🔥🔥🔥🔥🔥
Can you post the solutions of Google kickstart Round A and Round B
These are the such good problems to practice
the way you explain things is phenomenal...
thanks a lot
Welcome :)
@@techdose4u bhai you work in any MNC or u study in college(iit?)
MNC....
@@techdose4u which one.. if you don't mind brother 😅
Great!
Amazing!! You made it look so simple! Liked and Subscribed!
Thanks :)
awesome explanation and smooth ..... ! thanks a lot
Welcome :)
nice explanation about dp table.Thanks
Welcome :)
iiuc, the space complexity is O(n). One only needs one vector for the running minimums.
True. 2 maintaining 2 rows is sufficient. This is true for most table type DP programs.
Amazing video mate! explained thoroughly. Cheers
Very well explained. 👌
Amazing you solved all my doubts
Your videos are amazing plz do make more videos on DP ,it would be grateful Thanks
Thanks. Yes I will
Thank you so much for great explanation!!
Welcome :)
Great explanation brother
Thanks 🙂
Great Explanation!
i did without the dp vector. Since we could just perform modifications on the same given grid matrix.
Space Complexity O(1) :) . I submitted that way
Pleas share your code.
Great sir, as usual😋
Thanks :D
When he started getting into why greedy algorithms won't work I knew this was legit
:)
Nice explanation sir....but instead of taking an additional dp vector if we do changes in the given grid vector only then it will be o(1) space solution
👍🏼
Excellent!
Thanks :)
@7:38
grid[I][j]+ min( dp[ i-1][j], dp[I][j-1]) , there it was j-2.
Thank you for awesome explanations of dp table
Welcome :)
great video sir...........:)
Thanks
Nice Explanation
Thanks :)
very nice explanation
Thanks :)
What a color combination and style of *Leet code* in the thumbnail ? !!!! 😂
😅
It was a clickbait actually :D
@@marvellouschandan it wasn't 😂
THE BEST TUTORIAL
Thanks 😊
Nice explanation sir
Thanks :)
It's so easy to understand and I loved the break down from the simple to sophisticated approach!
I have a question re the recursive solution - why is the complexity O(2^n) and not O(2^(m*n))? if it means that there's 2 options to about each cell..? Thank you
Thanks. Actually our number of steps will always be (m+n) from top left to bottom right. So, you can say time will be 2^(m+n).
@@techdose4u That makes sense. Thank you!
Nice explanation, thanks!
Good Explanations!!
awesome sir
Thanks :)
greedy works if you properly define dp table. dp[i][j] denotes minimum path sum from (1,1) to (i,j)
The recursive way is DFS right with directions of right and below
Thanks, you explain very well :)
Welcome :)
if all 4 direction mvement would be allowed then what would be changes, will changes work in it, or completenew approach would be needed ???
Apply Dijkstra.
I wish this video came out 3 years ago when I took my algorithms class lol
:)
we can also do dijksta here right? the value in each cell can be the edge weight, which is pretty close to the dp solution.
You can
@@techdose4u can you please make a video on myers diff algorithm, (the one used in github file diff), it's not anywhere in youtube,
Awesome bro!!
Thanks :)
In line 11 of the code ,why did we initialize cols as
int cols=grid[0].size() and not just as grid.size()?
Because the number of cols are same in each row and grid[O] means no of cols. Grid.size means no of rows because it is a 2D matrix.
What is that Fast I/O in C++ line at the top? Is it necessary?
Can you post videos on segment tree??
Which is very useful for the purpose of comptetive programming
Already done. Search in videos.
I am stuck with a similar problem which is finding shortest path in 2D matrix from source to target which given in the problem and I have to return all i,j coordinates of the shortest path only. Please help.
works like magic
Nice :)
Dp approach is not working for some testcase can you please check it
can i say the time will be in recursive approach 2^(m*n) in worst case? so we use dp for n^2 time
if we can change the input matrix, we can use the same right? memory optimisation?
Yes if the array is mutable
If we can move up, down, left, and right then what changes do we have to make in the code?
Maybe try with Dijkstra graph algorithm.
Then you need track the path with visited array in order to bypass the cycle.
which tool are you using for whiteboard
Can we not use the extra space and use the given table for dp? I mean my testcase is ok but when i submit one solution is wrong
can we change the same logic ass required
when soure and destination or given??
can you tell boundary check condition in recursive Method.....
Out of bounds. Reaching the desired cell. Reject higher cost path (if using memoization).
Thank you😇
awesome
Thanks :)
What will be the boundary conditions for recursive approach
Out of bounds case.
def findPath(x:int,y:int):
if(x= len(grid) or y=len(grid[0])):
return
right = findPath(x,y+1)
down = findPath(x+1,y)
return min(right,down)+grid[x][y]
I used this method. I know you said recursive method won't work but I tried for my satisfaction. But when compiling it gives error because it isn't able to compare right and left when the boundary check returns null. Can you tell me where am I wrong
Code doesn't work for multiple testcases on gfg
how to calculate time complexity when we solve by bottom up dp approach.
TIME will be same either you do Top down or Bottom up because you will be doing same number of operations using the same algo and the same logic path. If you are getting confused then just rotate the matrix by 180 degrees them bottom up approach will become top down.
@@techdose4u Thanks for your quick reply. I am using recursive approach. Please see code.
ide.geeksforgeeks.org/BYt1SFzNms
Could someone please help me understand how the time complexity for the last solution is O(N^2)?
What should I do if i also have to count the number of paths through which We can reach the minimum cost as there can be more than one such paths?
Amazing explanation but why would anyone go with the DP approach if complexity is the same in both recursion and DP both
@tech dose what if add diagonal movement to it? how would we solve it then?
also in python 3 verson please
Memoization of recursive code to remove overlapping sub problem calls, will give O(N*N ) right?
It will depend on no of repeating subproblems. Actually 2^N is a much larger upper bound due to the constraint in movement. But yes, memoization should give approx N^2. But since we are still doing recursion, actual runtime can go much higher than table method if you get large matrix. So, table method is best for larger cases. I hope you got it :)
TQ bro!😃
Welcome :)
What will be the solution if we allow to move in all 4 directions?
👏👏👏👏👏👏
👏
Thank you!🔥
Welcome :)
Thank you
Welcome :)