Minimum Cost Path Dynamic Programming Explained with Code | Leetcode #64

Sdílet
Vložit
  • čas přidán 30. 07. 2020
  • Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
    NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we discuss the solution for the Minimum Cost Path problem where we are required to reach the bottom right corner from the top left corner with minimum cost. For a better understanding of the problem, click here: • Minimum Cost Path - Qu... . In this problem,
    1. You are given a number n, representing the number of rows.
    2. You are given a number m, representing the number of columns.
    3. You are given n*m numbers, representing elements of 2d array a, which represents a maze.
    4. You are standing in top-left cell and are required to move to bottom-right cell.
    5. You are allowed to move 1 cell right (h move) or 1 cell down (v move) in 1 motion.
    6. Each cell has a value that will have to be paid to enter that cell (even for the top-left and bottom-right cell).
    7. You are required to traverse through the matrix and print the cost of path which is least costly.
    For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
    #dp #dynamicprogramming #mincostpath
    Have a look at our result: www.pepcoding.com/placements
    Follow us on our FB page: / pepcoding
    Follow us on Instagram: / pepcoding
    Follow us on LinkedIn: / pepcoding-education

Komentáře • 146

  • @Y19IITK
    @Y19IITK Před 3 lety +20

    Sir trying to learn dp from a long time , but not able to do it, but looks like this time I will be able to do it .. as your teaching skills were god level .Thank you so much for posting these resources :-)

  • @subrat_ryuk2463
    @subrat_ryuk2463 Před 2 lety +2

    We can think of the storage and meaning in a different way too . Like we can think for any (i,j) cell where 0

  • @AbhishekJha-wm5oq
    @AbhishekJha-wm5oq Před 3 lety +10

    Most underrated channel of india

    • @Pepcoding
      @Pepcoding  Před 3 lety +16

      Beta, hamre desh ki janta ko dikhave vali cheeze zda aachi lgti h aur real content boring but with the love and support from you people Pepcoding will soon shine really bright.
      Till then, keep learning and keep loving Pepcoding.

    • @AbhishekJha-wm5oq
      @AbhishekJha-wm5oq Před 3 lety +3

      @@Pepcoding sahi baat hai sir ji wo how to earn in first year,falana thikana wale shortcuts wale videos hi log dekhte hai aur reality me jo dsa padhni hai wo nahi.

    • @siddhantsingh3392
      @siddhantsingh3392 Před 3 lety +1

      @@AbhishekJha-wm5oq sahi baat! I agree with you bro!! BTW from which college u r?

    • @ManishSharma-fi2vr
      @ManishSharma-fi2vr Před 3 lety

      @@Pepcoding can you also upload top down solution. It is really important because it tell us how to optimize recursive solution.

  • @MdWasim-su6ve
    @MdWasim-su6ve Před 2 lety

    Best Explanation so far , Thanks Sir

  • @udhavarora602
    @udhavarora602 Před 3 lety

    Sumeet sir, you are doing a thing of God for many students.
    There ar people who can't join coaching due to fees. But they want to learn. This will surely help them get amazing jobs. Indeed you are god sir. Kitni acchi hoti duniya agar aaj jaise aur log hote. My idol after ms Dhoni.

  • @davinder95
    @davinder95 Před rokem

    sir the way u just start explaining the question with the intro of the channel is just incredible

  • @Beingbansal
    @Beingbansal Před 3 lety +1

    amazing sir first year m hu phir bhi dp smooth lag rhi h aap ki vajah se.Thanks sir

  • @vsbelieve
    @vsbelieve Před 2 lety

    Amazing Explanation sir!!!

  • @vivekhattarge5795
    @vivekhattarge5795 Před 2 lety

    Ye badhiya tha..... Maja aa gaya!!

  • @jatinmaheriya2343
    @jatinmaheriya2343 Před 3 lety

    Thanks sir ! 💯👏🏻👏🏻👏🏻

  • @huoyuhao167
    @huoyuhao167 Před 2 lety +1

    Thank you sir, I was having a hard time understanding this problem and do, u made it possible, thank you a looooott!!!

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad it helped!
      Keep learning.
      And for better experience and well organised content visit nados.pepcoding.com

  • @aashishgoyal1436
    @aashishgoyal1436 Před 3 lety +2

    Thanks a lot for the brilliant explanation sir. u r amazing

  • @AshishGusain17
    @AshishGusain17 Před 2 lety

    thanks for these videos

  • @contactdi8426
    @contactdi8426 Před 3 lety +2

    Ohhhh Man !! You made it such a smooth ride. Wonderful sir 🤠

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thanks ✌️ and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @pravinmudaliyar3421
    @pravinmudaliyar3421 Před 2 lety +4

    Memoized and tabulated (opposite direction) solution:
    public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    int m = sc.nextInt();
    int n = sc.nextInt();
    int[][] arr = new int[m][n];
    for(int i=0; i= arr[0].length || arr[sr][sc] < 0){
    return Integer.MAX_VALUE;
    }
    if(sr == arr.length - 1 && sc == arr[0].length - 1) return arr[sr][sc];
    if(dp[sr][sc] != 0) return dp[sr][sc];
    int val = arr[sr][sc];
    arr[sr][sc] = -1;
    int left = minCostMem(arr, sr + 1, sc, dp);
    int right = minCostMem(arr, sr, sc + 1, dp);
    arr[sr][sc] = val;
    return dp[sr][sc] = val + Math.min(left, right);
    }
    private static int minCostTab(int[][] arr, int m, int n){
    int[][] dp = new int[m][n];
    for(int i=0; i

    • @azeemali6865
      @azeemali6865 Před 6 měsíci

      in the memorizing technique , maybe there is no need to mark a trace i.e arr[i][j] = -1 and remove after the call .? isn't

  • @fueLInjected29
    @fueLInjected29 Před 2 lety

    How to decide whether to fill dp matrix column wise or row wise and update it? Or will it not make any difference in result?

  • @dhruvtrehan8132
    @dhruvtrehan8132 Před 3 lety +13

    Sir, u did one mistake at 13:51 the value will be 18 instead of 16 in DP array (last column and third last row). Please tell me, if i am wrong :). You are a star sir, videos are awesome.

  • @RohitKumar-sq8mn
    @RohitKumar-sq8mn Před 3 lety

    God level explaination sir!!!

    • @Pepcoding
      @Pepcoding  Před 3 lety

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review
      g.page/Pepcoding/review?rc
      You can subscribe to our channel here
      czcams.com/users/Pepcodingabout?view_as=subscriber

  • @nitin9042
    @nitin9042 Před 2 lety

    Hope every student find sumeet sir. U r the best sir . Ajkl tw sapno me bhi aap aake pda jaate ho....u r awesome sir. Huge respect for you. By making your course public u have earned a lot of respect from the community

    • @Pepcoding
      @Pepcoding  Před 2 lety

      I request you to checkout nados.pepcoding.com and the content section there, it also has doubt support and career opportunities available free of charge.

  • @ayushbisht2689
    @ayushbisht2689 Před 3 lety

    Best Explanation on internet.

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @hemantsingh-zo3iw
    @hemantsingh-zo3iw Před 4 lety +2

    Awesome!!

  • @vishwassahu
    @vishwassahu Před 2 lety +1

    can we define the storage like,
    dp[ i ][ j ] : minimum cost to reach arr[ i ][ j ] from arr[0][0] , sot he answer will be at dp[ n ][ m ]

  • @jatinkumar4410
    @jatinkumar4410 Před 3 lety

    Great explanation

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thankyou beta!
      I am glad you liked it. If you like our efforts, will you like to review us here - g.page/Pepcoding/review?rc

  • @aniruddhrajput9239
    @aniruddhrajput9239 Před 3 lety

    Sir is meaning assign anywhere in array??

  • @sangammishra3670
    @sangammishra3670 Před 2 lety

    agr top se fill krein har cell ko as a target manke toh ?

  • @_inspireverse___
    @_inspireverse___ Před 2 lety

    Can we solve it using djikstra?

  • @Anand-zg6jv
    @Anand-zg6jv Před 2 lety +1

    sir, this code is not working for some test cases

  • @parasmyname784
    @parasmyname784 Před 2 lety

    Great explanation ....

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad you liked it!
      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @kshitijgupta592
    @kshitijgupta592 Před 2 lety

    This is bottom Up approach right?

  • @mickyman753
    @mickyman753 Před 3 lety

    sir level 1 aur level 2 ko use kaise krna hai ,uska ek separate video bn skta hai kya?

  • @ranavij
    @ranavij Před 3 lety

    Thnaks for the video at 8:36 value should be 18 (11+7) instead of 16

  • @shahimran7421
    @shahimran7421 Před 4 lety +5

    sir i started learning data structures which playlist to follow first

    • @Pepcoding
      @Pepcoding  Před 4 lety +2

      beta ye wali
      czcams.com/video/F8xQ5joLlD0/video.html
      Balki website se karo
      www.pepcoding.com/resources/online-java-foundation

  • @kewtomrao
    @kewtomrao Před 2 lety +1

    Please sir,if you could explain in English it would also be helpful for South Indians who are not well versed with Hindi.
    You are one of the best teacher I have seen till now!!

    • @Pepcoding
      @Pepcoding  Před 2 lety

      We have english channel also watch these videos there

  • @theuntoldtree
    @theuntoldtree Před 3 lety +5

    Tq,
    Target is to watch 8 videos per day🔥

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Good keep learning and keep loving Pepcoding😊

  • @swati8539
    @swati8539 Před 3 lety +3

    sir, can you please provide a recursive solution using the same approach (bottom-up )

    • @dheerajgupta3262
      @dheerajgupta3262 Před 3 lety +3

      import java.io.*;
      import java.util.*;
      public class Main {
      static int[][] dp = new int[101][101];
      public static void main(String[] args) throws Exception {

      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();
      int m = sc.nextInt();

      int[][] arr = new int[n][m];
      for(int i=0; i

  • @RitikKumar-bk6pj
    @RitikKumar-bk6pj Před 2 lety

    Sir nice explanation of this question solution but in geeks for geeks this solution is not working for all the test cases it pass only 10test cases out of 90

  • @2412Anand
    @2412Anand Před 3 lety

    sir, yahan pr n+1 and m+1 size ku ni liya?

  • @sahil3276
    @sahil3276 Před 3 lety

    Why are we going to left side from bottom right. Why not top?

  • @deepakgodiyal7226
    @deepakgodiyal7226 Před 3 lety

    Sir ye dp k ques memoization se kyu ni krre h ?

  • @avinashlanka6817
    @avinashlanka6817 Před 3 lety +2

    11+7 is 18 sir. U wrote it as 16 at 5th row last column

  • @rajeetgoyal6879
    @rajeetgoyal6879 Před 3 lety

    13:48 It's an error but still the algorithm is helpful 👍

  • @kunalpatidar2849
    @kunalpatidar2849 Před 3 lety

    Sir If we allow to move in 4 direction(up,down,left,right) then how we can solve this problem.
    and why in this case DP is not applicable ??.

  • @randomshit6035
    @randomshit6035 Před 3 lety +1

    sir isme agar greedy approach bhi lagate to ho jata na ? like every time we have choice of moving to horizontal or vertical so at every step starting from [0].. moves += min(hor,vert) krte jaate...2 + 6+0+4+3+4+0+4+1+2+0+8+2 = 36. In thatt case addtional storage n bnani pdti?Is this approach correct.

    • @AshutoshKumar-oo3hc
      @AshutoshKumar-oo3hc Před 3 lety +3

      No, the greedy approach won't work here because, let us suppose that an immediate horizontal cell has a cost of 3 whereas the immediate vertical cell has 7, we select the horizontal cell by using the greedy approach, but what if the immediate next of horizontal's are 100 and 95 whereas vertical one has 95 and 3. In that case, the greedy approach fails. (I am also a beginner but I think this justification would do, tell me if I am the wrong one bro 😅😅.)

    • @subbucs5674
      @subbucs5674 Před 3 lety +1

      @@AshutoshKumar-oo3hc Yes, your explanation is correct

  • @rajatsrivastava458
    @rajatsrivastava458 Před 2 lety

    what if we could go in direction right left up and down ??

    • @Pepcoding
      @Pepcoding  Před 2 lety

      For better experience and curated content sign up on nados.io and post your queries on community tab of NADOS.

  • @niru1931
    @niru1931 Před 3 lety

    Sir, wecan start to fill matrix from first row and first col.?

  • @kundan621
    @kundan621 Před 3 lety +1

    Goldman sachs me mere se ye question and stringify wala another question puchha gaya tha.

    • @manup7636
      @manup7636 Před 3 lety

      stringify wala question kya hai ?

  • @AryanSingh-gk2hi
    @AryanSingh-gk2hi Před 3 lety

    Sir, seems like in this video solution, you have taken the values in 'arr' array as cost of exiting that cell but on the website the question says "Each cell has a value that will have to be paid to enter that cell", which was confusing. please let me know if I am missing anything.

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.

    • @AryanSingh-gk2hi
      @AryanSingh-gk2hi Před 3 lety +1

      It's fine sir, I just wanted you to update the website to make things consistent.

  • @prashantranjan6487
    @prashantranjan6487 Před 3 lety

    Sir agar do paths ke values dp wali array Mai same hai toh kaise karenge??... Ham uss time kaise choose Krenge kaunsa path le??

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Humei to sirf value deni hai, kisi bhi cell se uttha lo

  • @hymnish_you
    @hymnish_you Před 3 lety

    Sir, I tried to solve it using memoization... And i used this condition for it:-
    if(memoize[i][j] != null && sum > memoize[i][j]) return Integer.MAX_VALUE;
    But it is telling TLE at last Test Case...
    Question:- Which can be the better condition using the memoization technique?

    • @horridhenry6789
      @horridhenry6789 Před 3 lety

      did u solved it using memoization ??

    • @utkarsh_108
      @utkarsh_108 Před 2 lety

      dude, this ques must be solved using tabulation on online judge. memoisation logic gives TLE everywhere

    • @sunnygoswami2248
      @sunnygoswami2248 Před 2 lety

      I tried this and it worked for all on the platform -
      int getLeastCostPath(vector maze, int row, int col, vector &dp1){
      if (row == maze.size()-1 && col == maze[0].size()-1)
      return dp1[row][col] = maze[row][col];
      if (row >= maze.size() || col >= maze[0].size())
      return INT_MAX;
      if (dp1[row][col] != INT_MAX)
      return dp1[row][col];
      int hpathCost = getLeastCostPath(maze, row, col+1, dp1);
      int vpathCost = getLeastCostPath(maze, row+1, col, dp1);
      int res = maze[row][col] + min(hpathCost, vpathCost);
      return dp1[row][col] = res;
      }

  • @SatnamSingh-cm2vt
    @SatnamSingh-cm2vt Před 4 lety +1

    is this top down approach? Since we are filling our table from bottom

  • @santoshreddy9963
    @santoshreddy9963 Před 2 lety

    sir please aapki site me doosre editor se submit karne ka option lagado.

  • @rahulagarwal6321
    @rahulagarwal6321 Před 2 lety

    How to solve this problem if we have to print the path as well.

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Visit- nados.pepcoding.com
      You can post your query on community tab.
      Don't forget to follow us on Instagram
      instagram.com/pepcoding/

  • @financewithsom485
    @financewithsom485 Před 3 lety

    sir please make videos on binary search when u will get time

    • @Pepcoding
      @Pepcoding  Před 3 lety

      it's there in the array section

  • @raghavsharma7896
    @raghavsharma7896 Před 3 lety

    Sir you could've simply started this solution with bottom up, from [0][0], woh mujhe intuitive laga, kyuki maine socha I do not know ki [n][m] ki cost kya hai. so shuru se start karo. Toh ye approach theek hai ya apke method ki habit dalun?

    • @Pepcoding
      @Pepcoding  Před 3 lety +6

      beta dono mei koi farak nahi hota. pehle cell ko meaning assign karo. firr choti problem dhundho kis taraf hai aur badi problem kis taraf. choti se badi problem ki taraf travel karo aur solve karo.
      jaise agar cell ka meaning hota ki current cell se bottom-right tak ka best cost yahan stored hai to chotti problem bottom-right mei hogi aur upar ki taraf travel karke solve hoga.
      agar cell ka meaning hota ki top-left se current cell tak ka best cost yahan stored hai to chotti problem top-left pe hoti aur upar se neeche ki taraf travel karke solva hota.
      3 steps -> give meaning to cell, identify smaller problem and larger problem (you will get the direction), travel in the direction and solve.

    • @raghavsharma7896
      @raghavsharma7896 Před 3 lety +1

      @@Pepcoding Thank you Sumit sir ab ekdum badhiya se clear ho gaya hai, apki vidoes se mera DP ka dar dur ho raha hai, baaki sab tutorial ratte lagwa dete hai par aap ache time leke bata rahe ho ki humne jo step liya hai kyu liya hai, I hope me saari dekh kar confident ho jaaun par dp bahot bada topic lagta hai. Sir kuch dino me ek baar live aao na aise he random baate karne ke liye😀😅? waise sir aapke jaisa great teacher koi nahi dekha ab tak, aap har taraf se great ho ❤️❤️❤️

  • @enigma2886
    @enigma2886 Před 3 lety

    agar down and right ki jaga all 4 direction move kare to ?

    • @fashionvella730
      @fashionvella730 Před 3 lety

      if you will move all the four sides it means you are getting back to the point from where you come

  • @krishnaverma7744
    @krishnaverma7744 Před 2 lety

    Till here all going good with DP, hope this time my DP fear will go away...
    thanks for putting so much effort to explain in so much detail
    Your content is really 24 carat gold :)
    I am making sure I like each video to do my bit at least.
    Thanks

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad it was helpful!
      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @pranavsuryavanshi5610
    @pranavsuryavanshi5610 Před 2 lety +1

    can anyone tell me,can we solve this problem using recursion???

    • @Pepcoding
      @Pepcoding  Před 2 lety +1

      For better experience and well-organised content visit on nados.pepcoding.com. Also you can post your query on Community tab.
      Don't forget to follow us on Instagram instagram.com/pepcoding/

  • @rishabhgoyal2835
    @rishabhgoyal2835 Před 3 lety

    sir best explanation sara samaj aagya
    2 doubts hai bs...
    1st is iss ques ko first time dekha hota to dp lagane ka kaise mind me aata ,, bcz jaise fib5 ko fib 4 , fib 3 ki jarurat padte hai and fib 4 ko 3 ki ..to vha to easily pta chlgya ...lekinn iss ques me repetetion nhi milpara ..
    2nd is memoizaton se agar krne chahe to iska solution milsakta hai?
    @pepcoding

    • @Rohan40
      @Rohan40 Před rokem

      when we are provide to choose any one out of all(in our case we have the choice to go either right or down ) use recurssion and when we have to find the optimal (i.e min ,max, largest,samaller etc) we use dp. and for every recursion problme with choice and to find the optial we use the dp

  • @devanshubilthare5277
    @devanshubilthare5277 Před 3 lety

    Sir, how to know that the question will be solved with dp.

    • @Pepcoding
      @Pepcoding  Před 3 lety +4

      Beta repeat question agar baar baar poocha jae to dp lagegi. Jaisa Fibonacci 5 ko fib4 air fib3 chaie. Aur fib4 ko fib3 aur fib2 chaie. Fib5 aur fib4 ko requirements mei fib3 common hai

  • @nitin9042
    @nitin9042 Před 2 lety

    The only teacher i love is sumeet sir.

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Thank you.
      For better experience and well-organised content visit nados.pepcoding.com

  • @23ritik
    @23ritik Před 3 lety

    DSA 450 QUESTIONS BY LOVE BABBAR solve kradoo sir youtube pr miljayegaa aapko please

  • @geetanegi2736
    @geetanegi2736 Před 3 lety

    Sir Is que ko recursion sa kr skta hai.??

  • @SCRIPTSAG
    @SCRIPTSAG Před 3 lety

    Sir question to 50 percent khud se kiya but Time complexity kya hogi sir eska thoda sa roughly explain ker do yhi pe samjh lenge

  • @SHASHANKRUSTAGII
    @SHASHANKRUSTAGII Před 2 lety

    free m jo apne seva ki hai, main ek din company m jane k bad apki seva karna chahta hu sir.

  • @pavalsudakar4063
    @pavalsudakar4063 Před 3 lety

    For the array {{1,1,20,10},{20,1,1,1},{1,1,20,20},{1,20,20,20},{1,20,20,20},{1,1,20,1}} The answer should be 30, but the output is different

  • @VinayKumar-vm1hg
    @VinayKumar-vm1hg Před 4 lety +2

    Sir memoization wala btaye please

    • @Pepcoding
      @Pepcoding  Před 4 lety +1

      beta sare questions ko memoization se redo karenge.

    • @VinayKumar-vm1hg
      @VinayKumar-vm1hg Před 4 lety

      @@Pepcoding
      Sir aapne to graph suru kr diya h
      Memoization wala sir easy hota h recursion lgao aur array ya matrix me store kr do

    • @anjneykumarsingh4461
      @anjneykumarsingh4461 Před 3 lety +1

      You can do yourself you did recursion well

  • @tusharnain6652
    @tusharnain6652 Před 2 lety

    Why always start from tabulation 😭😭😭

  • @mehakbhatia1314
    @mehakbhatia1314 Před 3 lety

    Iss program ka sirf thoda sa hint liya, till timestamp 7:24, fir khud se kar liya :D

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Bohot ache beta

    • @SCRIPTSAG
      @SCRIPTSAG Před 3 lety

      Same bro but video met dekho codes dekha kero usme thoda sa code dekho uske bad age ka soho ager nhi ata to video solution dekho

  • @devesh096
    @devesh096 Před rokem

    11+7 = 16 Kaise hoga Sir 08:34 ??

    • @manpreetsinghrana7751
      @manpreetsinghrana7751 Před rokem

      Calculation mistake hai .

    • @manpreetsinghrana7751
      @manpreetsinghrana7751 Před rokem

      36 36 30 26 26 35 31
      34 28 33 25 20 32 29
      29 28 24 21 17 24 24
      28 25 26 19 17 18 19
      22 21 21 20 13 12 18
      24 23 18 15 13 10 11
      29 27 25 20 19 10 2

  • @sahilverma4142
    @sahilverma4142 Před 4 lety +1

    sir 11+7!=16

  • @TheShantanu1395
    @TheShantanu1395 Před 2 lety

    Python code for above problem
    def minPathSum(self, grid: List[List[int]]) -> int:
    n = len(grid)
    m = len(grid[0])
    dp = [[0] * m for i in range(n)]
    for i in range(n-1, -1, -1):
    for j in range(m-1, -1, -1):
    if i == n - 1 and j == m - 1:
    dp[i][j] = grid[i][j]
    elif i == n - 1:
    dp[i][j] = dp[i][j + 1] + grid[i][j]
    elif j == m - 1:
    dp[i][j] = dp[i + 1][j] + grid[i][j]
    else:
    dp[i][j] = min(dp[i][j + 1], dp[i + 1][j]) + grid[i][j]
    return dp[0][0]
    Note - Please see that extra space can be avoided and grid can also be modified to save space

  • @simonkaranja3811
    @simonkaranja3811 Před 2 lety

    Hope you could use english

    • @Pepcoding
      @Pepcoding  Před 2 lety

      English content is available on nados.io
      Don't forget to follow us on Instagram instagram.com/pepcoding/

  • @atishayjain690
    @atishayjain690 Před 3 lety +1

    SUGGESTION: I think it will be much more convenient to solve this particular problem using recursion as it is not required to manually consider all the different cases for array traversal. Moreover, I felt that recursion is a bit more intuitive than tabulation for this particular problem.

    • @RAHUL-gf3ft
      @RAHUL-gf3ft Před 3 lety

      bro pls give the soln of this ques by recursion

  • @milad_mo
    @milad_mo Před 2 lety

    please describe in english

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Refer to nados.pepcoding.com for english and better experience.

  • @aakashyadav6228
    @aakashyadav6228 Před 3 lety +2

    Pepcoding giving away such premium content for free but who cares. People would watch love babbar(so called software engineer at amazon who can never teach you programming) giving shitty advices but won't try to learn free of cost at pepcoding.