dude i got an approach before but i wasn't sure of its implementation when i saw urs it's not totally same but the iteration part was missing in my approach now i got that thx dude appreciated it
When you said it is a doable hard, I figured lets try this till I get it accepted and after a bit of back and forth, I was able to get my code accepted. This is my C++ implementation: class Solution { public: int n,m; int drow[4]={-1,0,1,0}, dcol[4]={0,1,0,-1}; bool isValid(int &row, int &col){ return row>=0 && row=0 && col
i think we can directly write this statement right. res = 1+max(dfs(r+1,c,matrix[r][c]),dfs(r-1,c,matrix[r][c]),dfs(r,c+1,matrix[r][c]),dfs(r,c-1,matrix[r][c])) instead of those 5 lines of code??
If you want a bottom up DP solution, you can sort the values of the matrix in descending order (i used a heap, but a sorted array would work too) and process them in that order. You'll be guaranteed to have already calculated the LIPs of your larger neighbours as you visit each element, so you don't need DFS/recursion. Same time and space complexity of course.
Neet what are you thoughts on spaced repetition? Not writing the entire solution and memorizing it... instead, it would be cards in front: statement of the problem, back: Pattern (two pointers, DFS, etc) and any comments, maybe even drawings. Ideally this would help with just pattern recognition over time but wondering if you think it would be useless/ too much memorizing. Would use Anki for reference, thoughts?
i think it's a good idea, spaced repetition is shown to be very effective for memorization (that's if you're trying to memorize the blind 75/neetcode150, etc.) even better though is simple practice problem solving, so you can solve new problems the first time working through them. spaced repetition could probably help in learning patterns for this
Small addition, implement backtracking to slightly improve the running time. P.S. Solved this problem on my own in just 20 minutes. Can't stop thanking you.
A bit of trivia here. I just read the section on DFS in Intro to Algorithms (en.wikipedia.org/wiki/Introduction_to_Algorithms ) The theoretical kind of DFS they define there is actually always run on all the vertices of the graph. So anyone who read that book and was paying attention -- I wasn't :) :D -- would have this idea cold.
Amazing, thanks so much. I want to just add, I think these few lines look a bit cleaner than the 4 repeated lines of reassigning the 'res' variable. directions = [[1,0], [0,1], [-1,0], [0,-1]] for rowDir, colDir in directions: res = max(res, 1 + backtrack(row+rowDir, col+colDir, cur))
For god’s sake, pls start using simpler python(without syntax suger) or start using some other language such as Java, we are not here to learn python or see your language skills but program solving, i am referring your other video, cannot dare to watch this one bcoz I don’t wanna waste time learning python syntax, i am sorry if it looks rude
Not sure which video you're talking about, but there's nothing fancy in this code. The general ideas most of the time be easily translated between languages, and if you can't do that it's most likely that you don't understand the solution. Nothing related to the language. If anything, python is written like psuedo code, Java has so much boiler plate it makes things more complicated.
Typical Indian thinking he is smarter than people. If you dont like it in Python watch other videos. My primary language is JavaScript but i appreciate these videos.
@@NeetCode Please try and ignore these outlier comments. Most people love your Python solutions and I personally don't think your code can get any simpler! Please continue the great work!
@@mk17173n was there any need to point out the nationality ?? Indians have the best brains .... I think you have some hatred / jealousy for Indian people
@@mk17173n yeh i am also using js and python can be read like English language and we can convert into any language we want. There is no fancy coding here
10+ years coding and I still enjoy watching ur videos.
The way you make hard problems look so easy is amazing, thanks!
the first hard problem i've gotten without first viewing the solution ... feels good & hard work + Neetcode videos pays off :)
My code was kinda the same, but yours is a lot cleaner. That's something I really appreciate. Thanks for the great content. :)
dude i got an approach before but i wasn't sure of its implementation when i saw urs it's not totally same but the iteration part was missing in my approach now i got that thx dude appreciated it
Thanks!
Thank you so much!
Thanks for all your videos, they helped me so much. I landed my dream job. Please keep up ur channel! Merry Christmas!
Pls keep uploading....I am learning a lot.
You are my guide
Python Code: github.com/neetcode-gh/leetcode/blob/main/329-Longest-Increasing-Path-in-a-Matrix.py
Java Code (courtesy of a viewer - ndesai15): github.com/ndesai15/coding-java/blob/master/src/com/coding/patterns/dynamicprogramming/memoize/LongestIncreasingPath.java
Beautiful solution. Looking forward to more such videos
I literally search all the youtube I didnt find a guy explaining better than you
Keep on..
this one made me feel good about myself, cuz I knew right away it's a grid DFS with memoized storage
When you said it is a doable hard, I figured lets try this till I get it accepted and after a bit of back and forth, I was able to get my code accepted.
This is my C++ implementation:
class Solution {
public:
int n,m;
int drow[4]={-1,0,1,0}, dcol[4]={0,1,0,-1};
bool isValid(int &row, int &col){
return row>=0 && row=0 && col
Best Leetcode TH-cam channel!
i think we can directly write this statement right.
res = 1+max(dfs(r+1,c,matrix[r][c]),dfs(r-1,c,matrix[r][c]),dfs(r,c+1,matrix[r][c]),dfs(r,c-1,matrix[r][c]))
instead of those 5 lines of code??
I think so too. we are calculating max of res again and again, but we can do max ((left, right, top, bottom) + 1)
@@buttofthejoke yes.. exactly
yes but its more difficult to read
If you want a bottom up DP solution, you can sort the values of the matrix in descending order (i used a heap, but a sorted array would work too) and process them in that order. You'll be guaranteed to have already calculated the LIPs of your larger neighbours as you visit each element, so you don't need DFS/recursion. Same time and space complexity of course.
what do u mean u dont need dfs? how would u find the path tho
that's my first thought as well. (m*n)(log(m*n)) for sorting I guess
Great problem and explanation
The Gold Standard of Leetcode tutorials
Neet what are you thoughts on spaced repetition? Not writing the entire solution and memorizing it... instead, it would be cards in front: statement of the problem, back: Pattern (two pointers, DFS, etc) and any comments, maybe even drawings. Ideally this would help with just pattern recognition over time but wondering if you think it would be useless/ too much memorizing. Would use Anki for reference, thoughts?
i think it's a good idea, spaced repetition is shown to be very effective for memorization (that's if you're trying to memorize the blind 75/neetcode150, etc.)
even better though is simple practice problem solving, so you can solve new problems the first time working through them. spaced repetition could probably help in learning patterns for this
This was the best explanation, you made the problem so easy. Thank you!
very clean code !! like the way you use dictionary as cache
Small addition, implement backtracking to slightly improve the running time. P.S. Solved this problem on my own in just 20 minutes. Can't stop thanking you.
Thanks man any tips to approach problem like u do?
Thank you my bro your so good
Brilliant explanation!
Awesome as always ❤❤❤❤
Graph with Dynamic Programming
= Weapon of Mass Destruction
The problem was nicely broken down!
Brilliant solution.
Merry Christmas, let do some neetcode today
thank you you made dp problems no longer unapproachable to me 😭
Won’t the Error: List index out of range matrix[r][c]
How to calculate the number of longest path?
Hi Neetcode! Could you upload something in terms of bit masking? like 1915?
A bit of trivia here. I just read the section on DFS in Intro to Algorithms (en.wikipedia.org/wiki/Introduction_to_Algorithms ) The theoretical kind of DFS they define there is actually always run on all the vertices of the graph. So anyone who read that book and was paying attention -- I wasn't :) :D -- would have this idea cold.
Great Solution!!
please make a video on LeetCode 1499. Max Value of Equation
Thanks for the solution!
Would you mind making a video for 68: Text Justification?
Seems like this shouldn't really be labelled "hard". Some of the graph dfs medium problems are much harder
agreed, this was relatively simple for a graph problem, just need to implement cache
Very clean code ❤️
it should have easy tag
Amazing, thanks so much. I want to just add, I think these few lines look a bit cleaner than the 4 repeated lines of reassigning the 'res' variable.
directions = [[1,0], [0,1], [-1,0], [0,-1]]
for rowDir, colDir in directions:
res = max(res, 1 + backtrack(row+rowDir, col+colDir, cur))
how come backtracking isn’t used here? from each point, isn’t it possible to have several valid paths, where one path is the longest?
My question as well. Seems similar to the word search problem so I don’t get why it’s treated differently. Do you know 2 years later? Lol
If this matrix increased by 20% what is new marix
Really helpful!!
Isn't this just dp??
Is'nt not a hard.🤩
Best!!!
This is more like a medium problem. It's not hard
👏
For god’s sake, pls start using simpler python(without syntax suger) or start using some other language such as Java, we are not here to learn python or see your language skills but program solving, i am referring your other video, cannot dare to watch this one bcoz I don’t wanna waste time learning python syntax, i am sorry if it looks rude
Not sure which video you're talking about, but there's nothing fancy in this code. The general ideas most of the time be easily translated between languages, and if you can't do that it's most likely that you don't understand the solution. Nothing related to the language.
If anything, python is written like psuedo code, Java has so much boiler plate it makes things more complicated.
Typical Indian thinking he is smarter than people. If you dont like it in Python watch other videos. My primary language is JavaScript but i appreciate these videos.
@@NeetCode Please try and ignore these outlier comments. Most people love your Python solutions and I personally don't think your code can get any simpler! Please continue the great work!
@@mk17173n was there any need to point out the nationality ?? Indians have the best brains .... I think you have some hatred / jealousy for Indian people
@@mk17173n yeh i am also using js and python can be read like English language and we can convert into any language we want. There is no fancy coding here