09 - Unique Paths (Dynamic Programming for Beginners)

Поділитися
Вставка
  • Опубліковано 4 лис 2024

КОМЕНТАРІ • 101

  • @andreygrehov
    @andreygrehov  4 роки тому +3

    Next video: ua-cam.com/video/MSRTLzJDfag/v-deo.html
    Previous video: ua-cam.com/video/3hHmUszRXjw/v-deo.html

  • @denver-reed
    @denver-reed Місяць тому +3

    4 years later from your initial upload and this is still helping me greatly. Thank you, Andrey!

  • @LinkyLess
    @LinkyLess Рік тому +16

    I know you created this series 2 years ago, but it is a real gem for people who are just learning dynamic programming.
    Thank you for this!

  • @raghavddps2
    @raghavddps2 4 роки тому +26

    This series is so awesome that I will share it with all my friends at my university.

  • @shatadruroy3926
    @shatadruroy3926 4 роки тому +25

    Others: Teaching and making beginners understand a bottom up approach to DP problems is really tough!
    Andrey Grehov : Hold my beer
    Probably the only lecture series which lives up-to its name of "Dynamic Programming for beginners". I wish you keep uploading such amazing content more frequently! Great work

    • @AkkumBakkum-m5h
      @AkkumBakkum-m5h 6 місяців тому

      true bhai they give the taste of recursion in every problem which is not intuitive many times but after watching andrew videos i realise bottom up can be intuitive and easy thanks andrew for this big fann of work

  • @33galactus
    @33galactus 4 роки тому +7

    For the first time, I became fan of DP problems. Thanks a ton!!

  • @swathi.139
    @swathi.139 Рік тому +1

    Thank you very much for this wonderful course. I have struggled with DP problems. I am now clear after watching your videos.

  • @satyajitkamble1646
    @satyajitkamble1646 4 роки тому +15

    These videos are going to see exponential growth! Love the content!

    • @andreygrehov
      @andreygrehov  4 роки тому

      Oh, I wish, lol :) Thank you, Satyajit!

  • @MukilShelby
    @MukilShelby 3 роки тому +3

    If anyone asked me about Dynamic Programming, I would just share this playlist.
    Such a detailed course. Kudos, man!

  • @sgtduckduck
    @sgtduckduck Рік тому

    Hey I just want to say huge thanks. None of my coursework really touched DP, and even memoization is something I've rarely gotten to touch on in my own work. But DP has been a HUGE blindspot for me when preparing for coding interviews, and thanks to this series I feel SO CONFIDENT.
    You've broken it down for me in a way that just instantly clicked and I really appreciate it. Your series deserves more views and I can't recommend it enough to people. Thank-you.

  • @kshitijb9416
    @kshitijb9416 7 місяців тому

    Nice transition to grids man!
    You've made it real easy to grasp. Thanks!

  • @shaurya478
    @shaurya478 8 днів тому

    It is the best it can gets. Thanks Andrey.

  • @sammyj29
    @sammyj29 2 роки тому +1

    I am so happy to have discovered this series!! Thanks Andrey! You have a gift for teaching!! Hope you make videos on other important and complex topics too!

  • @JPN-bx3yd
    @JPN-bx3yd 3 роки тому

    I was able to solve the coin change and knapsack problem by watching this course. Great content. Keep it up!

  • @eh3276
    @eh3276 3 роки тому

    This is the best tutorial i have seen until now thank you .

  • @shensean1784
    @shensean1784 4 роки тому +1

    it is a very clear and well-organized series. Really appreciate your effort. I know how hard it is for a father to squeeze such an amount of time.

  • @user-zy3jg8ox7s
    @user-zy3jg8ox7s 2 роки тому

    This series is super valuable! Thank you so much for making these videos Andrey!!!

  • @shubhampathak1080
    @shubhampathak1080 2 роки тому

    I stumbled upon this channel while revising a few DP topics, this series is by far the best one as you've presented a very systematic and a clear approach in solving these problems. Kudos and I genuinely hope you get some free time to make more of these (maybe on backtracking or graphs) in general to help out folks. Thanks !

  • @dailyviralpodcastss
    @dailyviralpodcastss 4 роки тому +1

    Wooooooooooooooooooooooow that's amazing, Thank you so much! The way you explain it is so easy adn understable I finally can Understand what is actually DP Thank you so much again!

  • @munkhbayar3940
    @munkhbayar3940 3 роки тому

    Such a brilliant channel & content, today I've just watched the first 9 episodes without getting off for a sec. Every DP videos I'd had starts with the change-making problem and I've always kind of ended up with questions like 'how & why' at the end of those videos. But you taught me there were many prerequisites which should've gotten before. Can't wait for the next videos. and graph-related topics. Thx sir!.

  • @abhinavpandey6261
    @abhinavpandey6261 Рік тому

    Great tutorials so far , binged watched in one day :P

  • @josecorral9645
    @josecorral9645 3 роки тому +1

    Hey thank for this series of videos, a couple of months ago I had an interview on a FAANG company which I failed because I did not understand dynamic programming. This course has helped me a lot, I still don't master DP but this series of videos is helping me a lot.
    So again thanks.

  • @abdujabbormirxoliqov9676
    @abdujabbormirxoliqov9676 4 роки тому +2

    Cool! your videos really help to understand dynamic programming more deeply!

  • @Empilor
    @Empilor Рік тому

    Thanks Andrey, great explanation, useful course :) it’s hard to find such content

  • @hannnah689
    @hannnah689 3 роки тому

    So lucky find this video, super useful!

  • @Ub3rmike
    @Ub3rmike 4 роки тому +1

    This problem ended up being the daily coding challenge question on LeetCode on 6/29/2020. I hadn't even seen this video yet, but I was able to solve the problem in a matter of minutes because the the idea of deriving a recurrence relation in the k steps problem (sum the paths to the k previous solutions) applies to the 2d matrix context (sum the paths to the previous "up" and "left" solutions)!

  • @ashokkumarkrishnamsetty6533
    @ashokkumarkrishnamsetty6533 4 роки тому

    Thanks for this. This is amazing, your framework just works

  • @張宗旻
    @張宗旻 10 місяців тому

    such a great introduction !!!!

  • @shivamtyagi9936
    @shivamtyagi9936 4 роки тому

    This is my 3rd playlist , m watching on DP ....& yes u r better than the best!!!
    Tnks sir!! U r an inspiration!!

  • @damaroro
    @damaroro Рік тому

    dude where are u now ? we need more video like this, this the best DP problem explanation in UA-cam

    • @andreygrehov
      @andreygrehov  Рік тому

      Hey Damar. Thank you. I wish I could go back to UA-cam. Extremely busy at work at AWS :(

  • @sairamaj
    @sairamaj 2 роки тому

    Thank you very much. Very nice and thanks for your time. really appreciate it.

  • @marcousosewelle5501
    @marcousosewelle5501 4 роки тому +1

    Subscribed. Brilliant series! Your communication, delivery and content are on point. Well done. Keep up the amazing work :-)

  • @NiranjanChandarraj1990
    @NiranjanChandarraj1990 4 роки тому +3

    Thanks for the awesome content, Andrey! Can we discuss some problems with top down approach and see when we would actually use it?

    • @andreygrehov
      @andreygrehov  4 роки тому +1

      Thank you, Niranjan. Great idea. I'll make a separate video in which we'll go over the top-down approach.

  • @vissper1
    @vissper1 2 роки тому

    Appreciate your work!

  • @BhargavSolankisolankibhargav
    @BhargavSolankisolankibhargav 4 роки тому

    Thank you for doing this. Well explained.

  • @abdulrahmankhalid4634
    @abdulrahmankhalid4634 3 роки тому

    Thanks for the content

  • @ananthganiga425
    @ananthganiga425 3 роки тому

    Great Videos. Fantastic. Thanks alot for your effort

  • @smitdavey4834
    @smitdavey4834 4 роки тому

    Great series, Andrey! It would be great to see you walk through some of the most popular DP interview problems from top companies and applying your framework to them. Especially when it comes to graphs and searching, it gets really confusing. As the other comment mentioned, top-down would be helpful too and what exactly the difference is and how to spot it. Thanks again - appreciate the ELI5 explanations.

    • @andreygrehov
      @andreygrehov  4 роки тому

      Thank you, Smit. Yeah, very good points. The top-down vs bottom-up is in the works. I'll release it soon.

  • @jameskanyi7376
    @jameskanyi7376 3 роки тому

    Good news. DP well explained

  • @fayezmaria8688
    @fayezmaria8688 2 роки тому

    Just amazing thanks

  • @myrachoantonio8832
    @myrachoantonio8832 Місяць тому

    This amazing thank you so much for the tutorials bi

  • @竹千代-n4c
    @竹千代-n4c 4 роки тому

    Thanks for the series!

  • @Enzoerb
    @Enzoerb 4 місяці тому

    We can also do this same problem starting from the back, right?
    Because then the value on each dp would be the ways in which this point can lead you to the end
    Then dp[m-1][n-1] = 1, because there is only 1 way to get to the end from the end
    Then we would tun the for
    i = m-1; i

  • @ashvanijaiswal9207
    @ashvanijaiswal9207 3 роки тому

    Hey Andrey, Thanks a lot. Your Dynamic Programming course is really really big hit. Can you please make a series on backtracking and recursion.

  • @karimkhattaby
    @karimkhattaby 4 роки тому +4

    Thanks for the amazing content bro! your method stuck to my head.
    However I'm still not sure how to apply the same method to top-down questions like coin change, target sum, and largest square sub-matrix.
    I'm specifically struggling in finding the base case and to find a pattern to create the equation. If you have any tips that can help me I'd really appreciate it. Thanks

    • @andreygrehov
      @andreygrehov  4 роки тому +8

      Hey Karim! Oh, these are interesting problems. We'll actually review all of them during the course. I don't know why, but iterative bottom-up approach is easier to me. If I'm not wrong, the plan is to review the Coin Change problem the following Sunday. Thank you so much for watching and commenting these videos. It's a huge motivation for me.

  • @siljapoulose4688
    @siljapoulose4688 4 роки тому

    Great explanations !!!

  • @daham94
    @daham94 4 роки тому

    Great Work!!!

  • @AkkumBakkum-m5h
    @AkkumBakkum-m5h 6 місяців тому

    thank you sir so muchhhhh you are inspiration to me

  • @glensee7506
    @glensee7506 3 роки тому

    I love it, thanks!

  • @sumodbadchhape9823
    @sumodbadchhape9823 4 роки тому

    Thank you. Great explanation! 👌

  • @enmanuelcruzdejesus765
    @enmanuelcruzdejesus765 2 роки тому

    nice work!!

  • @nikhilthapa9300
    @nikhilthapa9300 Рік тому

    Sad to see you stopped, should have kept them coming, the way you explain with examples and categorize them and give frameworks to solve a problem rather than spoon feeding solutions is unique.

    • @andreygrehov
      @andreygrehov  Рік тому

      Thanks, Nikhil. Yea, super busy at work. Don't really have time for UA-cam :(

  • @coreytodtaylor
    @coreytodtaylor 6 місяців тому

    Hey Andrey, that a great playlist, I haven't seen anything better. I'd like to have payment subscription on your tutorials!

    • @andreygrehov
      @andreygrehov  6 місяців тому +1

      Hehe, I actually thought about that.

  • @glennpavel4800
    @glennpavel4800 3 роки тому

    thanks for share!

  • @acidroot7126
    @acidroot7126 4 роки тому +1

    Wow! Thanks!!!

  • @koh8614
    @koh8614 4 роки тому

    Really nice content!

  • @princem8779
    @princem8779 3 роки тому

    Thank you so much!!!

  • @RedionXhepa
    @RedionXhepa 4 роки тому

    Nice video ! Thanks a lot

  • @arjunprashanth
    @arjunprashanth 4 роки тому

    Huge fan of this series!
    I was wondering if the space complexity can be reduced further. As every time we update a value in the matrix, we only need the value to its left and the value above. So , we really do not need to store the other values.
    I was thinking of something like this:
    row = [1]*m # creating 1D array of size m
    for row in range(1, n):
    for col in range(1, m):
    row[col] = row[col-1] + row[col] # adding values to the left of the current cell (takes care f[i][j-1]) and adding itself (takes care of f[i-1][j]) to the current value to reuse the same row in the next iteration.
    return row[-1]
    Let me know what you think of this! @Andrey

    • @andreygrehov
      @andreygrehov  4 роки тому

      Thank you, Arjun. It's totally possible. There is a high chance that my solutions are not the most optimal solutions out there. My goal is to teach you guys to conquer DP problems. Once you know how to approach it, optimization should not be a problem.
      As for your code, I haven't tested it, but from a first glance, I think it makes sense. Consider running it through a few test cases to make sure.
      Thanks for watching the course!

  • @tmkalyan8157
    @tmkalyan8157 4 роки тому

    Loving the series so far, I was always confused about Dynamic Programming, but kudos to you, amazing content!
    Just a quick question, if u are trying to find the max profit, u say the path is 0 -> 3 -> 4 -> 4 -> 2 = 13, but should it not be 0 -> 2 -> 1 -> 3 -> 4 -> 4 -> 2 -> 0 = 16?
    The sub-problems look to be taking a greedy approach maybe?

    • @andreygrehov
      @andreygrehov  4 роки тому +1

      Thank you so much! Appreciate it. As for your question, not really. We are only allowed to move either down or right at any point in time. So, in your example, 0 -> 2 -> 1 -> 3... we can't move from 1 to 3, because we would have to make a left move, which is not allowed.
      Also, as for the greedy approach, it wouldn't work in this problem. I wanted to mention it, but forgot. Check out this example:
      S 2 2 2 2
      1 1 1 1 2
      3 3 3 3 E
      The greedy approach would take you to the route of 2's, because 2 is always greater than 1, but such solution would not be correct. Does it make sense?

    • @tmkalyan8157
      @tmkalyan8157 4 роки тому

      @@andreygrehov yeah makes sense, got it I didnt see it explicitly mentioned about not allowing a left anywhere, so i got confused! Thanks for the quick reply and explanation!

  • @ranjith1102
    @ranjith1102 6 місяців тому

    Very useful videos.but I don’t see videos in other topics.It would be more helpful for beginners if you make more videos on other DSA.

  • @vedaanish2015
    @vedaanish2015 4 роки тому

    Thanks for your videos. your video makes to "Stop searching DP on the internet again".

  • @abhishekthakur7675
    @abhishekthakur7675 4 роки тому

    ​ @Andrey Grehov Hey, great series so far. I am enjoying the tutorials.
    But I have a doubt on today's session. Let's say the matrix is
    :-
    S 1 1 1 10
    2 1 1 1 1
    2 1 1 2 E
    By the approach you just explained, it will choose the path
    S->2->2->1->1->2->E
    Which is not optimal, right?

    • @kshitijsabale1857
      @kshitijsabale1857 4 роки тому +3

      maximum is calculated between the dp() function and not the a[i][j] ...
      when we say that max ( dp[i-1][j],dp[i][j-1]) we compare total weight to reach to that two elements of the matrix and not just the weight of the two elements ...

  • @rrrrandall
    @rrrrandall 3 роки тому

    Would this problem/technique be possible if it it was allowed to go in any direction without "back tracking"? Rather than only being allowed to move right and down.

    • @rrrrandall
      @rrrrandall 3 роки тому

      I think you would need to do a depth first search and keep track of each path. I'm not sure if there would be any DP improvement.

  • @jamesvick8066
    @jamesvick8066 3 роки тому

    This series is so good it could become a tv show lol

  • @RajSingh-dl2lk
    @RajSingh-dl2lk 3 роки тому

    thank you.

  • @Yaya-fu2wk
    @Yaya-fu2wk 3 роки тому

    After watching your videos, I feel DP is no longer magic! Would you also consider making algorithms videos?

  • @theshreyansjain
    @theshreyansjain 2 роки тому

    comment for the algo! great video

  • @yizhang7027
    @yizhang7027 3 роки тому

    Transition function is recurrence relation, right?

  • @eittorres
    @eittorres 4 роки тому

    Awesome

  • @martinjoseph1398
    @martinjoseph1398 4 роки тому

    we have a problem with this function.. max(f[i-1][j], f[i],[j-1]) it fails for this grid
    5 1 50
    4 2 1
    4 4 1

    • @andreygrehov
      @andreygrehov  4 роки тому

      Hey Martin, I just tried your matrix and it works well. Could you show me your code?
      Here is mine: play.golang.org/p/scaVDyP1Fv-

    • @martinjoseph1398
      @martinjoseph1398 4 роки тому

      @@andreygrehov Thank you for your response. It's pretty quick.
      It's my bad, your function works. I did top down approach rather than bottom up.
      My code: jsfiddle.net/#&togetherjs=USfC5M5Q4o

  • @JamshadAhmad
    @JamshadAhmad 4 роки тому +2

    First view and like.

  • @II_xD_II
    @II_xD_II 4 роки тому

    isnt most profitable path greedy

  • @ahmadbodayr7203
    @ahmadbodayr7203 2 роки тому

    First of all I want to thank you
    then I want to tell you that I really did see good in you and you should really look into ISLAM ❤

  • @starbloods0013
    @starbloods0013 3 роки тому

    can someone review my code? i tried solving it recursively:
    F(i,j){
    if i > 0 AND j > 0{
    best = F(i-1,j) + F(i,j-1)
    }
    if i > 0{
    best = F(i-1,j)
    }
    if j>0{
    best = F(i,j-1)
    else
    return 1
    }
    return best

    • @starbloods0013
      @starbloods0013 3 роки тому

      the only thing i left out was a look up table so that the code won't keep solving problems it already solved