No video

Longest Increasing Path in a Matrix - Leetcode 329

  Рет қаралды 60,332

NeetCode

NeetCode

Күн бұрын

Пікірлер: 69
@prempeacefulchannel
@prempeacefulchannel 2 жыл бұрын
The way you make hard problems look so easy is amazing, thanks!
@rommeltito123
@rommeltito123 2 жыл бұрын
10+ years coding and I still enjoy watching ur videos.
@dj1984x
@dj1984x 9 ай бұрын
the first hard problem i've gotten without first viewing the solution ... feels good & hard work + Neetcode videos pays off :)
@freshlyminted6999
@freshlyminted6999 2 жыл бұрын
My code was kinda the same, but yours is a lot cleaner. That's something I really appreciate. Thanks for the great content. :)
@shaikadam1828
@shaikadam1828 3 ай бұрын
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
@mingchenma4679
@mingchenma4679 2 жыл бұрын
Thanks for all your videos, they helped me so much. I landed my dream job. Please keep up ur channel! Merry Christmas!
@sauravchandra10
@sauravchandra10 Жыл бұрын
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
@girirajrdx7277
@girirajrdx7277 2 жыл бұрын
Pls keep uploading....I am learning a lot. You are my guide
@ngneerin
@ngneerin 2 жыл бұрын
Beautiful solution. Looking forward to more such videos
@minciNashu
@minciNashu 2 жыл бұрын
this one made me feel good about myself, cuz I knew right away it's a grid DFS with memoized storage
@andrewyuan7881
@andrewyuan7881 2 жыл бұрын
Great problem and explanation
@Septix
@Septix 2 жыл бұрын
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?
@dj1984x
@dj1984x 9 ай бұрын
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
@rezajeffrey7970
@rezajeffrey7970 2 жыл бұрын
I literally search all the youtube I didnt find a guy explaining better than you Keep on..
@dk20can86
@dk20can86 2 жыл бұрын
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.
@mubarizsaeed187
@mubarizsaeed187 Жыл бұрын
what do u mean u dont need dfs? how would u find the path tho
@xiaohuisun
@xiaohuisun Жыл бұрын
that's my first thought as well. (m*n)(log(m*n)) for sorting I guess
@KnuthMorris
@KnuthMorris Ай бұрын
Brilliant solution.
@sakethkumarpeddi2089
@sakethkumarpeddi2089 7 ай бұрын
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??
@buttofthejoke
@buttofthejoke 7 ай бұрын
I think so too. we are calculating max of res again and again, but we can do max ((left, right, top, bottom) + 1)
@sakethkumarpeddi2089
@sakethkumarpeddi2089 7 ай бұрын
@@buttofthejoke yes.. exactly
@hwang1607
@hwang1607 5 ай бұрын
yes but its more difficult to read
@vincentlius1569
@vincentlius1569 2 жыл бұрын
very clean code !! like the way you use dictionary as cache
@jamespolemeni5475
@jamespolemeni5475 Жыл бұрын
The Gold Standard of Leetcode tutorials
@BeingAsh22
@BeingAsh22 2 жыл бұрын
This was the best explanation, you made the problem so easy. Thank you!
@hgk7027
@hgk7027 2 жыл бұрын
Best Leetcode KZbin channel!
@NeetCode
@NeetCode 2 жыл бұрын
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
@aryanyadav3926
@aryanyadav3926 Жыл бұрын
Brilliant explanation!
@AryanSingh-zv5ch
@AryanSingh-zv5ch Жыл бұрын
Thanks man any tips to approach problem like u do?
@jitbanerjee6875
@jitbanerjee6875 Жыл бұрын
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.
@NhanSleeptight
@NhanSleeptight 2 жыл бұрын
Merry Christmas, let do some neetcode today
@ronniey4231
@ronniey4231 9 ай бұрын
Awesome as always ❤❤❤❤
@bhuvneshsingh3347
@bhuvneshsingh3347 2 жыл бұрын
Thanks!
@NeetCode
@NeetCode 2 жыл бұрын
Thank you so much!
@nishantingle1438
@nishantingle1438 2 жыл бұрын
Graph with Dynamic Programming
@henryCcc8614
@henryCcc8614 2 жыл бұрын
= Weapon of Mass Destruction
@peeckle1657
@peeckle1657 2 жыл бұрын
Great Solution!!
@nuamaaniqbal6373
@nuamaaniqbal6373 2 жыл бұрын
The problem was nicely broken down!
@Ragdoll333-q5l
@Ragdoll333-q5l 2 жыл бұрын
Hi Neetcode! Could you upload something in terms of bit masking? like 1915?
@matthewzhang7330
@matthewzhang7330 2 жыл бұрын
Thanks for the solution!
@matthewzhang7330
@matthewzhang7330 2 жыл бұрын
Would you mind making a video for 68: Text Justification?
@ram_pande8039
@ram_pande8039 2 жыл бұрын
Very clean code ❤️
@HalfJoked
@HalfJoked Жыл бұрын
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))
@georgegeorge581
@georgegeorge581 2 жыл бұрын
Really helpful!!
@paraskumar693
@paraskumar693 2 жыл бұрын
it should have easy tag
@vadimkokielov2173
@vadimkokielov2173 2 жыл бұрын
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.
@romo119
@romo119 Жыл бұрын
Seems like this shouldn't really be labelled "hard". Some of the graph dfs medium problems are much harder
@dj1984x
@dj1984x 9 ай бұрын
agreed, this was relatively simple for a graph problem, just need to implement cache
@hanjiang9888
@hanjiang9888 2 жыл бұрын
thank you you made dp problems no longer unapproachable to me 😭
@user-gg1qc8ld5x
@user-gg1qc8ld5x 2 жыл бұрын
Won’t the Error: List index out of range matrix[r][c]
@Eggleweb97
@Eggleweb97 2 жыл бұрын
please make a video on LeetCode 1499. Max Value of Equation
@minato6536
@minato6536 2 жыл бұрын
How to calculate the number of longest path?
@tshotblue22
@tshotblue22 2 жыл бұрын
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?
@user-uc9dp1gh4d
@user-uc9dp1gh4d 6 ай бұрын
If this matrix increased by 20% what is new marix
@senthilkumar5
@senthilkumar5 2 жыл бұрын
Best!!!
@shavvasatya7131
@shavvasatya7131 Жыл бұрын
Is'nt not a hard.🤩
@priyanshudeep1008
@priyanshudeep1008 2 жыл бұрын
Isn't this just dp??
@EduarteBDO
@EduarteBDO 7 ай бұрын
This is more like a medium problem. It's not hard
@AseshShrestha
@AseshShrestha 2 жыл бұрын
👏
@lakhbawa
@lakhbawa 2 жыл бұрын
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
@NeetCode
@NeetCode 2 жыл бұрын
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.
@mk17173n
@mk17173n 2 жыл бұрын
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.
@alokesh985
@alokesh985 2 жыл бұрын
@@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!
@Ak-um1yg
@Ak-um1yg 2 жыл бұрын
@@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
@Mr_corporate_gamer
@Mr_corporate_gamer 2 жыл бұрын
@@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
Split Array Largest Sum - Leetcode 410 - Python
16:51
NeetCode
Рет қаралды 80 М.
Snakes and Ladders - Leetcode 909 - Python
21:22
NeetCode
Рет қаралды 50 М.
Dad Makes Daughter Clean Up Spilled Chips #shorts
00:16
Fabiosa Stories
Рет қаралды 7 МЛН
Nurse's Mission: Bringing Joy to Young Lives #shorts
00:17
Fabiosa Stories
Рет қаралды 14 МЛН
Reconstruct Itinerary - Leetcode 332 - Python
17:38
NeetCode
Рет қаралды 67 М.
Jump Game - Greedy - Leetcode 55
16:28
NeetCode
Рет қаралды 234 М.
Edit Distance - Dynamic Programming - Leetcode 72 - Python
21:00
Open the Lock - Leetcode 752 - Python
14:22
NeetCode
Рет қаралды 39 М.
Shortest Bridge - Leetcode 934 - Python
14:51
NeetCode
Рет қаралды 37 М.
Maximal Square - Top Down Memoization - Leetcode 221
19:50
NeetCode
Рет қаралды 65 М.
Coin Change - Dynamic Programming Bottom Up - Leetcode 322
19:23
Decode String - Leetcode 394 - Python
16:26
NeetCode
Рет қаралды 84 М.