Minimum Falling Path Sum - Leetcode 931 - Python
Vložit
- čas přidán 28. 07. 2024
- 🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🧑💼 LinkedIn: / navdeep-singh-3aaa14161
🐦 Twitter: / neetcode1
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
Problem Link: leetcode.com/problems/minimum...
0:00 - Read the problem
0:30 - Recursive Explanation
3:35 - Recursive Coding
8:00 - DP Explanation
10:42 - DP Coding
leetcode 931
#neetcode #leetcode #python
Missed your daily videos bro.
Please don't skip posting videos😅
To be fair , questions asked in that time frame , were not that deep
Let's write some more neetcode 🎉.
I use subtitles always.. and it gives let's write some neat code 😂😂
Great explanation as always. Thank you very much.
Finally you are back!!❤
thanks bro for uploading the video.......I thought you stopped solving leetcode
Welcome back :D
One can adapt this problem to find the maximum falling path too!
bro in the moring I looked for your video, I could solve this by my own and then you publishing this video which is the exact same algorithm 😅
I got my Amazon offer yesterday, largerly thanks to your channel!
HAPPY FOR YOU ❤️🚀🔥
sometimes u are literally the only light in my eternal dark hell
Finally!
When will you stream next?
Is the DP solution top-down or bottom-up?
Is it truly a solution for medium difficulty problem? was much harder to understand than most of hard problem for me..
Bro is gonna pretend like he didn't go missing for a few days
At line 8, should not that be c >= 0 instead of c > 0.
Could do += line 10 and use inf instead of float(“inf”)
what is "line 10"?
@@phatboislymmatrix[r][c] = matrix[r][c] + …. instead just do matrix[r][c] +=
@@phatboislym you can avoid by managing index inside the indexing as well like this:
I used extra dp matrix but you can use the same input array to do this as well
def minFallingPathSum(self, matrix: List[List[int]]) -> int:
m, n = len(matrix), len(matrix[0])
dp = [[0 for _ in range(n)] for _ in range( m+1)]
for i in range(m-1, -1, -1):
for j in range(n):
dp[i][j] =min(matrix[i][j]+dp[i+1][max(0,j-1)], matrix[i][j]+dp[i+1][j], matrix[i][j]+ dp[i+1][min(n-1,j+1)])
return min(dp[0])
Please do daily neetcode problems or update the community posts with links to earlier solved problems please
I do not want to watch any other channel
Sure, will do!
why i am getting tle???
class Solution {
public int minFallingPathSum(int[][] matrix) {
int n=matrix.length,m=matrix[0].length;
int min=Integer.MAX_VALUE;
int dp[][]=new int[n][m];
for(int row[]:dp)
{
Arrays.fill(row,-1);
}
for(int i=0;i
A nice problem to revise classic DP solutions. Thanks for video, I was missing your daily solutions!
BTW @NeetCodeIO, I wonder wether you've bought a leetcode T-Shirt for leetcoins? :)
Anyone getting TLE for running recursive solution in Java?
This is my code:-
class Solution {
public int dfs(int row,int column,int[][] matrix,HashMap s){
int n=matrix.length;
if(row==n )
return 0;
if(column==n || column