Would like to see your explanation of longest palindromic subsequence (516 on leetcode). Your explanation for checking if general input string is a palindrome was great
Great and simple solution. Once recommendation though is that when explaining such problem - demonstrate how the 2d array is filled visually, because it's hard to understand otherwise.
Not only the solution was great, but most importantly I found the explanation on how to come up with it amazing. I really struggle with these dynamic programming problems and you really made it seem so easy!
There is a simple close form solution to this problem: (m-1+n-1) choose (m-1) Every path is composed of: m-1 moves down n-1 moves right m-1+n-1 moves total Choose a path is equivalent to determining when we choose to move down (m-1) out of all optional moves (m-1+n-1)
its a permutation-combination problem, basically the total being n!/a!/b! where a+b = n... in first example, a = 2 and b = 1 since the robot can move at max twice towards right and at max one downwards... total will always be 3 moves, which is 3!/2!/1! = 3... in second. similarly a = 6 and b = 2, n = 8 and 8!/6!/2! = 28 and so on... this isnt technically a programming challenge at all, and certainly not for Dynamic Programming...
This is an older video but for future viewers it's worth pointing out that there is a more optimal way to solve this problem by treating it as a combinations problem instead of a programming problem. For every MxN graph you will always take (M - 1) downward movements and (N - 1) right movements. Every unique path is just a combination of these down and right movements. The math formula to calculate the number of unique combinations would be: (Total number of movements)! / ((Number of downward Movements)! * (Number of right movements)!) Total number of movements would be (M + N - 2) Number of downward movements would be (M - 1) Number of right movements would be (N - 1) The only part you would have to program is the factorial calculation and your space complexity would be O(1) and your runtime complexity would be O(M + N) due to the factorial calculations.
Was wondering if anyone would point this out. No videos ever seem to mention the combinatorial solution for this prpblem, only DP. Sometimes it helps to know your combinatorics / discrete math :) Btw, I believe the binomial coefficient computation can be implemented more efficiently than O(m+n) -- that is, O(min(m,n))
Kevin your videos are outstanding, an absolutely tremendous resource. You’re personable and your explanations are excellent - so much easier to understand than anything else I’ve encountered.
Am I just dumb or is there a reason people aren't solving this problem recursively? m = 3 n = 7 d = 0 r = 0 count = 0 def recurse(d,r): global count if d == m-1 and r == n-1: count += 1 if d < m-1: recurse(d+1,r) if r < n-1: recurse(d,r+1) recurse(d,r) print(count)
The usual approach for dynamic programming: 1. come up with a recursive algorithm (which is slow), 2. Come up with a dynamic algorithm (way waster) that bases the logic off of the recursive one. Build a 1-d or 2-d table as needed using loop/s and recursive algorithm logic BUT use indexing instead of recursive calls for example recCall(x-1,y-1) = recCall[x-1][y-1].
hey you could just use 1D array(sizeof rows, init to 1s), as you only care about one row at a time, to calculate the next one. you can calculate each step with previous one (still going on loop with i and j) but just summing up dp[j] = dp[j] + dp[j-1] and then returning dp[n-1] so youll get it with O(n) space. hope this helps someone!
I have watched many other videos but your explanations are so simple and easy to understand and they are alll 6-8 minutes others take 20-30 min and they confuse with lot of unnecessary details :-)
This was my solution without using DP. Using recursion instead. class Solution { int paths = 0; public int uniquePaths(int m, int n) { findEnd(m,n, 0, 0); return paths; } void findEnd(int m, int n, int cur_row, int cur_col){ if (cur_row == m-1 && cur_col == n-1){ paths++; return; } if(cur_row < m-1){ findEnd(m,n, cur_row+1, cur_col); } if(cur_col < n-1){ findEnd(m,n, cur_row, cur_col+1); } } } Basically treating the grid as a graph and using depth first search till you get to the end. Once you get to the end, then you increment the paths counter. However, leetcode said time limit exceeded on this on an input of 23,12 When I run the function with that input, i get the answer in like 1 second on my computer. So i guess they are very particular about the time efficiency for this one
this question belongs to a programming paradigm known as dynamic programming(dp), just give it a read on sites ike gfg and u will understand how to identify if it is a dp problem and how to get to this approach. best of luck.
An alternative way of thinking could be treating array as a graph. Doing dfs (without marking ofc) and increasing counter whenever we reach final point will give result. Just might be easier for someone.
I would love to know how you can calculate the unique paths if you were allowed to move both UP and LEFT as well (without overlapping any previously traversed squares). I'm working on a project that will need to incorporate this but so far the only examples I can find are for unique paths that calculate the shortest routes only, i.e. a matrix that looked like [[0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0]] should, in theory, have 4 unique paths but most codes I've found only validate 3. I assume it's just more complex version of what you've done above?
Hi Kevin, why [1][0], [2][0] ......& [0][1], [0][2]....are filled with 1. If [1][0] has 1, then [2][0] should have 2 because to come down we have to travel all cell of the column [0]. Sorry if I am wrong.
Hey Kevin, instead of writing two for loops for all the 1s, we can directly assign them in the main loop(inside 2 for loops) like this: int[][] res = new int[m][n]; for(int i=0;i0) res[i][j] = res[i-1][j]+res[i][j-1]; } } } return res[m-1][n-1]; Also, I wrote another solution using DFS, can you tell me why is LC showing time limit exceeded for this? It gives the same output as your code if I run in eclipse. private static int unique(int m, int n) { int[][] matrix = new int[m][n]; return findpaths(0,0,matrix,m,n) ; }
static int findpaths(int i,int j,int[][] matrix,int row, int col){ if(i=row || j=col) return 0;
I could solve this by brute force, but it did not pass leetcode specs. Is there any way, any hint on how to identify DP problems? Maybe a video about it would be great!
Anytime! If you like my explanations be sure to check out the interviewing service I created thedailybyte.dev/?ref=kevin I'd recommend joining the annual plan if you can!
Because since its dynamic programming, you are looping through each cell and finding how many ways there are to get to that cell by calculating the different ways from the cells it could of came came from (top or left). Meaning you are entering the different ways to get to that cell you are on into the cell so the last cell of the matrix, which would be matrix[m-1][n1], will have the answer to all the possible ways to get to the last cell in the matrix. top left corner to bottom right. if you just put matrix[m][n] youll get an out of bounds. since m is the number of rows if there are 4 rows but the first row is matrix[0] the last row would be row 3 aka matrix[m-1]
Jigyasu Prakash anytime! If you need help with these kinds of problems sign up for the interviewing service I created thedailybyte.dev/?ref=kevin I recommend joining the annual tier if you can!
Hi, Kevin. Thanks for your channel. I really like your video very much. Kevin Can you please help me in understanding this. Here in example- diagram they show the 2D- Array for 7 * 3 as Rows=3 and column=7. After that in their first example where m=3 and n=2. Again they are taking Rows=2 and column=3 represented by int[][] dp = new int[n][m]. Thats why they get answer like 1. Right -> Right -> Down 2. Right -> Down -> Right 3. Down -> Right -> Right 1 -> 1 -> 1 1 -> 1 -> 1 R R 1 -> 1 -> 1
D | D| | D
1 -> 1 -> 1 R R But in you code you take m = row and n = column and create int[][] dp = new int[n][m]. And thus the 2D Array I got is .
1 1 1 1 1 1
I know , I wrote very much, But may be I got confused. Please help me out in getting this.
I think this happens because either we took int[] dp = new int[3][2] or we took int[] dp = new int[2][3], we got the same answer. we can use row and column interchangeably.
I've done this problem before and had to stare at code for a long time to get it. You made it really straight forward. How would the solution be different if we could move in all 4 directions and we had an arbitrary start and end on a grid? Also I'd love if you could do the minimum window sliding problem. I get the concept, but the code sometimes is a bit hard to grasp. Thanks, Kevin!
Happy to hear my videos was helpful Frank, but don't stress about it it's a tough problem just keep working hard! My initial thoughts on what you're proposing is that...assuming you can't revisit cells (otherwise there would be infinite unique paths) I think it would be pretty similar except you would consider the other 2 directions as well when calculating the unique dp[i][j] and you wouldn't be returning the bottom right corner of the dp matrix anymore. Let me know your thoughts and thanks for the support Frank!
The dfs solution is actually O(2^n) since each recursive call makes 2 more calls such as uniquePaths(m-1, n) + uniquePaths(m, n-1). It times out since this takes exponential time
bcos, though in dp it seems like we have o(n^2) time complexity but actually we only fill up a 2d array and that takes really no time to compute and fill it, and time shown as zero is compilation time, if u will practice some more dp problems, u will find some more zeroes, so best of luck!
it isnt. its a permutation-combination problem, basically the total being n!/a!/b! where a+b = n... in first example, a = 2 and b = 1 since the robot can move at max twice towards right and at max one downwards... total will always be 3 moves, which is 3!/2!/1! = 3... in second. similarly a = 6 and b = 2, n = 8 and 8!/6!/2! = 28 and so on... this isnt technically a programming challenge at all, and certainly not for Dynamic Programming...
Thanks. rewrite it in python def findpath(m,n): nums=[[0 for i in range(n)]for j in range (m)] for i in range(m): nums[i][0]=1 for j in range(0,n): nums[0][j]=1 for i in range(1,m): for j in range(1,n): nums[i][j]=nums[i-1][j]+nums[i][j-1] print("Array Value ",nums) print("The max value is",nums[m-1][n-1]) findpath(17,3)
I'll see what I can do. In the meantime if you need help with these kinds of questions be sure to join the interviewing service I created: thedailybyte.dev/?ref=kevin I'd recommend joining the annual plan if you can!
Kevin, do you remember any employer (except Google, Facebook possibly) asking to solve a DP problem on a real whiteboard/phone interview? Based on my experience, I don't remember such situation..
Aside from the companies you mentioned I can't say I've been asked DP problems explicitly, but you never know so I think it's best to prepare for them. Furthermore, chances are if you can do the dp problems you can do any other problems so it's always good to study the hard stuff :)
Thanks Anshika! If you like my explanations be sure to join the interviewing service I created to help people learn the most popular interview questions and topics! thedailybyte.dev/?ref=kevin I recommend joining the annual tier if you can! :)
i have a question why do u prefer solving problems using java not C++ is there a reason or you just java i used to solve problems using C++ but once i saw ur videos am considering java what do u think ?
Don't beat yourself up, these questions are hard!!! It took me a lot of practice and a lot of hours of studying to do these kinds of problems so don't worry just keep working hard!
Not too sure what the purpose of this video is aside from seeing you code. You just blurt out how to calculate the unique paths for any cell, which is fine but you don’t explain any thought process for us to follow that leads you to figuring out that DP function. It’s like saying “Here’s the answer, you know why it’s the answer? Look it works so that why”. Also you can optimize the space usage here to be O(Min(n,m)) so this is only optimal for time.
What other problems should I go over?
please go through more DP problems.
Would like to see your explanation of longest palindromic subsequence (516 on leetcode). Your explanation for checking if general input string is a palindrome was great
@@thekewlwaffle I'll see what I can do thanks for the suggestion!
@@rahulshrivastava3040 You got it!
@@rahulshrivastava3040 You got it!
Great and simple solution. Once recommendation though is that when explaining such problem - demonstrate how the 2d array is filled visually, because it's hard to understand otherwise.
Not only the solution was great, but most importantly I found the explanation on how to come up with it amazing. I really struggle with these dynamic programming problems and you really made it seem so easy!
Miguel Manchola if you help with these kinds of problems be sure to subscribe to The Daily Byte! thedailybyte.dev/
Out of all other DP problems, THIS is the one which made me understand how easy DP solution can be .. Will apply for other similar problems, cool ...
There is a simple close form solution to this problem:
(m-1+n-1) choose (m-1)
Every path is composed of:
m-1 moves down
n-1 moves right
m-1+n-1 moves total
Choose a path is equivalent to determining when we choose to move down (m-1) out of all optional moves (m-1+n-1)
True, just to add it could be (m+n-2) Choose (n-1) also(same as down, we could also choose n-1 right moves).
its a permutation-combination problem, basically the total being n!/a!/b! where a+b = n... in first example, a = 2 and b = 1 since the robot can move at max twice towards right and at max one downwards... total will always be 3 moves, which is 3!/2!/1! = 3... in second. similarly a = 6 and b = 2, n = 8 and 8!/6!/2! = 28 and so on... this isnt technically a programming challenge at all, and certainly not for Dynamic Programming...
This is an older video but for future viewers it's worth pointing out that there is a more optimal way to solve this problem by treating it as a combinations problem instead of a programming problem.
For every MxN graph you will always take (M - 1) downward movements and (N - 1) right movements. Every unique path is just a combination of these down and right movements. The math formula to calculate the number of unique combinations would be:
(Total number of movements)! / ((Number of downward Movements)! * (Number of right movements)!)
Total number of movements would be (M + N - 2)
Number of downward movements would be (M - 1)
Number of right movements would be (N - 1)
The only part you would have to program is the factorial calculation and your space complexity would be O(1) and your runtime complexity would be O(M + N) due to the factorial calculations.
Was wondering if anyone would point this out. No videos ever seem to mention the combinatorial solution for this prpblem, only DP. Sometimes it helps to know your combinatorics / discrete math :)
Btw, I believe the binomial coefficient computation can be implemented more efficiently than O(m+n) -- that is, O(min(m,n))
Kevin your videos are outstanding, an absolutely tremendous resource. You’re personable and your explanations are excellent - so much easier to understand than anything else I’ve encountered.
Am I just dumb or is there a reason people aren't solving this problem recursively?
m = 3
n = 7
d = 0
r = 0
count = 0
def recurse(d,r):
global count
if d == m-1 and r == n-1:
count += 1
if d < m-1:
recurse(d+1,r)
if r < n-1:
recurse(d,r+1)
recurse(d,r)
print(count)
The usual approach for dynamic programming: 1. come up with a recursive algorithm (which is slow), 2. Come up with a dynamic algorithm (way waster) that bases the logic off of the recursive one. Build a 1-d or 2-d table as needed using loop/s and recursive algorithm logic BUT use indexing instead of recursive calls for example recCall(x-1,y-1) = recCall[x-1][y-1].
There is that nice white wall behind you. You should buy some markers to match and draw on it. :)
Finally getting some intuitions on dynamic programming! Thank you. First DP question I was able to do before watching your solution lol.
Thank you for the straight forward explanation.I'm in love with your channel
Anytime and I'm so happy to hear that share it with others I wanna help as many people as possible and thanks for your support!!!
Hi Kevin. Nice video. Very easy to follow. What about Big O? Would you says O(n2) (quadratic) for time complexity and the same for space?
hey you could just use 1D array(sizeof rows, init to 1s), as you only care about one row at a time, to calculate the next one. you can calculate each step with previous one (still going on loop with i and j) but just summing up dp[j] = dp[j] + dp[j-1] and then returning dp[n-1] so youll get it with O(n) space. hope this helps someone!
I have watched many other videos but your explanations are so simple and easy to understand and they are alll 6-8 minutes others take 20-30 min and they confuse with lot of unnecessary details :-)
This was my solution without using DP. Using recursion instead.
class Solution {
int paths = 0;
public int uniquePaths(int m, int n) {
findEnd(m,n, 0, 0);
return paths;
}
void findEnd(int m, int n, int cur_row, int cur_col){
if (cur_row == m-1 && cur_col == n-1){
paths++;
return;
}
if(cur_row < m-1){
findEnd(m,n, cur_row+1, cur_col);
}
if(cur_col < n-1){
findEnd(m,n, cur_row, cur_col+1);
}
}
}
Basically treating the grid as a graph and using depth first search till you get to the end. Once you get to the end, then you increment the paths counter.
However, leetcode said time limit exceeded on this on an input of 23,12
When I run the function with that input, i get the answer in like 1 second on my computer. So i guess they are very particular about the time efficiency for this one
Can I see this is actually an exercise I did in my elementary school in a math contest lol. Thanks to that experience!
I would like to call you DP-Master.
wow that actually makes a lot of sense
Amazing approach brother please tell me
how to get that approach
I am looking at problem couldnt able to do it & simply looking at solution.
this question belongs to a programming paradigm known as dynamic programming(dp), just give it a read on sites ike gfg and u will understand how to identify if it is a dp problem and how to get to this approach. best of luck.
It's possible to bring down the space complexity to O(n), by overwriting on the same row again and again.
Top-bottom approach of dymanic progamming. Which of dp problems could be solved without recursion?
Thank you Kevin!! iwanna be like you when i grow up... wait.. i'm a grown ass adult 😭
is there a way you can memoize your solution to reach a more optimal solution?
Now it's clear! I can visualize it! Thanks Kevin🙏🙏
Super happy to hear that Seunghun and anytime!!! :)
Can't we use dfs(right), dfs(down) recursive calls. Once you get to the end, then increment the num_paths counter?
An alternative way of thinking could be treating array as a graph.
Doing dfs (without marking ofc) and increasing counter whenever we reach final point will give result.
Just might be easier for someone.
I would love to know how you can calculate the unique paths if you were allowed to move both UP and LEFT as well (without overlapping any previously traversed squares). I'm working on a project that will need to incorporate this but so far the only examples I can find are for unique paths that calculate the shortest routes only, i.e. a matrix that looked like [[0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0]] should, in theory, have 4 unique paths but most codes I've found only validate 3. I assume it's just more complex version of what you've done above?
Keep up the amazing work Kevin! Your videos are a blessing!
Excellent explanation. You got a new subscriber.
Awesome and it does.
True subscribers will know the satisfaction in those words... 😃
Thanks Jovan :)
Hi Kevin, why [1][0], [2][0] ......& [0][1], [0][2]....are filled with 1. If [1][0] has 1, then [2][0] should have 2 because to come down we have to travel all cell of the column [0]. Sorry if I am wrong.
Hey Kevin, instead of writing two for loops for all the 1s, we can directly assign them in the main loop(inside 2 for loops) like this:
int[][] res = new int[m][n];
for(int i=0;i0)
res[i][j] = res[i-1][j]+res[i][j-1];
}
}
}
return res[m-1][n-1];
Also,
I wrote another solution using DFS, can you tell me why is LC showing time limit exceeded for this? It gives the same output as your code if I run in eclipse.
private static int unique(int m, int n) {
int[][] matrix = new int[m][n];
return findpaths(0,0,matrix,m,n) ;
}
static int findpaths(int i,int j,int[][] matrix,int row, int col){
if(i=row || j=col) return 0;
if(i==row-1 && j == col-1) return 1;
return findpaths(i+1,j,matrix,row,col)+findpaths(i,j+1,matrix,row,col);
}
Please help :(
I could solve this by brute force, but it did not pass leetcode specs. Is there any way, any hint on how to identify DP problems? Maybe a video about it would be great!
Thanks for the videos. They are really helpful. It will be great if you can discuss time and space complexity as well after each question.
You made this so easy for me thanks a lot man.
This took me hours to understand but finally I got it!
Great video. It helps if you can bring visual description as well to the video.
What's the Time & Space Complexity ?
sir,can u please teach us about recursion...because i am new to programming and these topics are difficult to understand..
This was the first DP question I solved
Thanks for this approach
Anytime! If you like my explanations be sure to check out the interviewing service I created thedailybyte.dev/?ref=kevin I'd recommend joining the annual plan if you can!
Wow. Pretty difficult concepto explained tooooooo easily and clear. Thank you
btw the problem link in the description is incorrect. it is this one leetcode.com/problems/unique-paths/
Is there anyway we can do this with like dfs or something?
I thought it was a DFS problem
The key question to the sub-problem definition & as well as the solution is @ #4:37
I didn't understand why we return dp[n-1][m-1] , other parts were clear.
Because since its dynamic programming, you are looping through each cell and finding how many ways there are to get to that cell by calculating the different ways from the cells it could of came came from (top or left). Meaning you are entering the different ways to get to that cell you are on into the cell so the last cell of the matrix, which would be matrix[m-1][n1], will have the answer to all the possible ways to get to the last cell in the matrix. top left corner to bottom right. if you just put matrix[m][n] youll get an out of bounds. since m is the number of rows if there are 4 rows but the first row is matrix[0] the last row would be row 3 aka matrix[m-1]
I've done this problem before. But today I feel like I can do this problem even after decades if asked
I swear whoever first thought of this is a mutant.
Awesome solution.. Thanks bro..
Kevin, you are so awesome!
The made DP seems very simple.. Thank you so much sir🙏🙏
Jigyasu Prakash anytime! If you need help with these kinds of problems sign up for the interviewing service I created thedailybyte.dev/?ref=kevin I recommend joining the annual tier if you can!
Man u made it look so easy. Thank you legend
Audio level's much better :) great video!
Woooo so happy to hear that! Thanks for letting me know Kuba :)
Hi, Kevin. Thanks for your channel. I really like your video very much.
Kevin Can you please help me in understanding this.
Here in example- diagram they show the 2D- Array for 7 * 3 as Rows=3 and column=7.
After that in their first example where m=3 and n=2. Again they are taking Rows=2 and column=3 represented by int[][] dp = new int[n][m].
Thats why they get answer like
1. Right -> Right -> Down
2. Right -> Down -> Right
3. Down -> Right -> Right
1 -> 1 -> 1
1 -> 1 -> 1
R R
1 -> 1 -> 1
D | D| | D
1 -> 1 -> 1
R R
But in you code you take m = row and n = column and create int[][] dp = new int[n][m]. And thus the 2D Array I got is .
1 1
1 1
1 1
I know , I wrote very much, But may be I got confused. Please help me out in getting this.
I think this happens because either we took
int[] dp = new int[3][2] or we took
int[] dp = new int[2][3],
we got the same answer. we can use row and column interchangeably.
Love your videos. You literally make every question look easy.
Thanks Shalin really appreciate that!
I've done this problem before and had to stare at code for a long time to get it. You made it really straight forward. How would the solution be different if we could move in all 4 directions and we had an arbitrary start and end on a grid?
Also I'd love if you could do the minimum window sliding problem. I get the concept, but the code sometimes is a bit hard to grasp.
Thanks, Kevin!
Happy to hear my videos was helpful Frank, but don't stress about it it's a tough problem just keep working hard! My initial thoughts on what you're proposing is that...assuming you can't revisit cells (otherwise there would be infinite unique paths) I think it would be pretty similar except you would consider the other 2 directions as well when calculating the unique dp[i][j] and you wouldn't be returning the bottom right corner of the dp matrix anymore. Let me know your thoughts and thanks for the support Frank!
Also thanks for the problem suggestion I'll see what I can do :)
I was doing via dfs, it worked for some inputs and after that gave me timeout. Still wondering why? as DFS is also O(N)
The dfs solution is actually O(2^n) since each recursive call makes 2 more calls such as uniquePaths(m-1, n) + uniquePaths(m, n-1). It times out since this takes exponential time
How the time will be 0 whether it takes O(n^2) time complexity??
bcos, though in dp it seems like we have o(n^2) time complexity but actually we only fill up a 2d array and that takes really no time to compute and fill it, and time shown as zero is compilation time, if u will practice some more dp problems, u will find some more zeroes, so best of luck!
Thanks Kevin!It is an amazing strategy to solve this problem. I tried using combinations in python, but failed. Thanks a lot
Thanks Anna and don't worry about it it's a tough problem just keep working at it!!!
Put the code up on github pls.Also if you do the beginning explanation with some graphics or powerpoint I think your videos will improve a lot.
Thanks for the advice Equaco! I'd always thought about putting diagrams or graphics on the videos maybe I'll start doing it!
Can't this just be solved in O(1) with combinatorics ?
The formula is (m+n)!/(m!*n!). But it's still O(n).
No. Even if combinatorics, calculating the actual value is O(n).
@@ArkabandhuChowdhury formula is (m-1+n-1)!/ (m-1)!(n-1)!
I can't believe that I didn't realise that this was a DP question in a grid, damn it!!
it isnt. its a permutation-combination problem, basically the total being n!/a!/b! where a+b = n... in first example, a = 2 and b = 1 since the robot can move at max twice towards right and at max one downwards... total will always be 3 moves, which is 3!/2!/1! = 3... in second. similarly a = 6 and b = 2, n = 8 and 8!/6!/2! = 28 and so on... this isnt technically a programming challenge at all, and certainly not for Dynamic Programming...
This really helped sir, thanks a lot!
Happy Teachers Day Sir, appreciate your hard work and teaching!
Please make a video on how to match a string and a pattern without using
You could also show us how to print those unique paths, as usually that is the follow up question in the interview.
I am thinking of using backtracking to print every unique path.
What are your thoughts?
I am loving this channel ♥️
you are brilliant sir!!!! please keep on going
Thats was so easy !! You are so clear in your explainations. Thanks :)
Thanks for the kind works Shwetz and anytime! :)
i have learn a lot from you. thank you so much.
Thanks.
rewrite it in python
def findpath(m,n):
nums=[[0 for i in range(n)]for j in range (m)]
for i in range(m):
nums[i][0]=1
for j in range(0,n):
nums[0][j]=1
for i in range(1,m):
for j in range(1,n):
nums[i][j]=nums[i-1][j]+nums[i][j-1]
print("Array Value
",nums)
print("The max value is",nums[m-1][n-1])
findpath(17,3)
nice one mate
thanks for your videos (great work, nice explaination);
Can you make a video on Unique Paths III please?
I'll see what I can do. In the meantime if you need help with these kinds of questions be sure to join the interviewing service I created: thedailybyte.dev/?ref=kevin I'd recommend joining the annual plan if you can!
Your are awesome, only one request just boost volume its bit low
amazing videos
hard to visualize. explanation with pic would have helped
Plz use paper or paint to explain
Can you do reconstruct itinerary in leetcode using dfs and backtracking? Thanks!
I'll see what I can do thanks for the suggestion!
Sir thanks a lot . You are doing a great job.
Thanks Rahul!
Kevin, do you remember any employer (except Google, Facebook possibly) asking to solve a DP problem on a real whiteboard/phone interview? Based on my experience, I don't remember such situation..
Aside from the companies you mentioned I can't say I've been asked DP problems explicitly, but you never know so I think it's best to prepare for them. Furthermore, chances are if you can do the dp problems you can do any other problems so it's always good to study the hard stuff :)
Thanks
Hi Kevin Could you please upload a solution video on LeetCode 711 - Number of Distinct Islands II Problem ?
I'll see what I can do, thanks for the suggestion Naresh!
Jump Game (LeetCode). Please solve this question, using DP. Thanks.
I'll see what I can do thanks for the suggestion!
OMG How do you explain so well! I m still dumbstruck!
Thanks Anshika! If you like my explanations be sure to join the interviewing service I created to help people learn the most popular interview questions and topics! thedailybyte.dev/?ref=kevin I recommend joining the annual tier if you can! :)
@@KevinNaughtonJr Will definitely give it a try!
Actual link: leetcode.com/problems/unique-paths/
i have a question why do u prefer solving problems using java not C++ is there a reason or you just java i used to solve problems using C++ but once i saw ur videos am considering java what do u think ?
How did you become good at solving problems ?this what I struggle with
Don't beat yourself up, these questions are hard!!! It took me a lot of practice and a lot of hours of studying to do these kinds of problems so don't worry just keep working hard!
Kevin Naughton Jr. thanks man keep making these videos they do help.Do you have a book or any resource you’d recommend?
@@Mal-wk3uq Anytime and don't worry I will! I would recommend cracking the coding interview and the elements of programming interviews!
why are you returning dp[m-1][n-1]? Why not dp[m][n] ?
Not too sure what the purpose of this video is aside from seeing you code. You just blurt out how to calculate the unique paths for any cell, which is fine but you don’t explain any thought process for us to follow that leads you to figuring out that DP function. It’s like saying “Here’s the answer, you know why it’s the answer? Look it works so that why”. Also you can optimize the space usage here to be O(Min(n,m)) so this is only optimal for time.
Mr. Mystiks you’re welcome to leave the optimized space solution here