DP 11. Triangle | Fixed Starting Point and Variable Ending Point | DP on GRIDS

Sdílet
Vložit
  • čas přidán 7. 09. 2024

Komentáře • 919

  • @takeUforward
    @takeUforward  Před 2 lety +191

    I need your support, and you can do that by giving me a like, and commenting "understood" if I was able to explain you.

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

      Please correct the link of the problem

    • @satyamsrivastava9083
      @satyamsrivastava9083 Před 2 lety

      Understood Sir .

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

      understood

    • @hrithikgupta1457
      @hrithikgupta1457 Před rokem

      Instead of declaring cur array length of n size in space optimisation part, we can declare cur size in for loop of i, of ith size, as at starting the cur will be of size ith(n-2) only and at last it will be of size 1.

    • @aayushranjan5572
      @aayushranjan5572 Před rokem

      pls hindi me vdo bana do hm lg ko smjhna h phle fir code krna h

  • @eshandhok2591
    @eshandhok2591 Před 2 lety +154

    People Please read (for dummies like me):
    This is the first lecture from where I can directly write memoized code, if put my mind into it can write tabulated one too, also my code worked every single time.
    >> Started this series and found the first few videos okay like i was understanding them but then came lecture 6 and 7, Ninja training and the unique path grid. procrastinated on them for many days like 5-6, used to skip or watch them but could'nt retain them, so used to rewatch similarly. I then decided to get really into it, to understand in depth. Drew recursion trees for the problems gave 2-3 hours on those two videos (L7 and L6) and now how things work is in my brain I just translate what I think into code.
    TLDR: Just stick with it, give each video as much time as you need to understand, striver has made each video concise at god level such that every video is important as well as connected. Like in this video, I just had to think about how sub recursion will happen, heck didn't even think, it was soo intuitive that I just wrote code, submitted, got accepted.

    • @prakritisaraf6124
      @prakritisaraf6124 Před rokem +7

      same bro same

    • @infinityzero2321
      @infinityzero2321 Před rokem +1

      Exactly same thing happened with me ... ninja problem gives you a sudden blow but then after that suddenly the need to write whole recursive them memoized was gone i could directlt write the space opti for until this vid

    • @LowkeyCoder
      @LowkeyCoder Před 9 měsíci

      this was not for me i am a bigger idiot i procastinated for like 2 weeks ki bhaiya c++ mein padfhate hai but found out pseudo code is enough and also learnt how to write in c++ so mera yaha aake double faida hua !

    • @anantsaxena5454
      @anantsaxena5454 Před 3 měsíci

      Same Bro Same

    • @ayushbaliyan6249
      @ayushbaliyan6249 Před měsícem

      Us Bhai Us

  • @jidgesanathkumar8038
    @jidgesanathkumar8038 Před 2 měsíci +28

    There is a famous saying in our language
    "NUV DEVUDU SAAMI" (I feel you are the god of dsa teaching, coding )
    Thank you man!!
    The man, The myth, The legend
    One piece STRIVER..👑

  • @infinityzero2321
    @infinityzero2321 Před rokem +18

    Even after saying that he wont do the recursion tree , he did draw it ... Hats off to dedication and your motto to help every student

  • @prempeacefulchannel
    @prempeacefulchannel Před 2 lety +38

    That space optimization is so godlike! This will surely impress interviewers! Thanks a lot striver bro

    • @monubhargav346
      @monubhargav346 Před 8 měsíci

      Even you will not require extra space other than given grid if you calculate maximym inplace

  • @dennyage4791
    @dennyage4791 Před 2 lety +51

    UNDERSTOOD !
    This is the first dp problem, i did it from very scratch (from recursion) to space optimisation by myself ..
    Thank u ,for providing such next 🔥🔥 content .

  • @rishikagarg4646
    @rishikagarg4646 Před rokem +32

    Just after 4 days of watching dp videos, I was able to solve this question (Recursive, memorization and tabulation ) on my own in less than 6 mins, Feeling so Proud !! I can't thank Striver enough for providing such an amazing content, It's really next level.

  • @ethanhunt3671
    @ethanhunt3671 Před 2 lety +18

    In tabulation, inside nested loop, if we run loop for j from 0-->i, then also everything will be fine (as dp[i][j] is dependent on dp[i+1][j] and dp[i+1][j+1], so for row i, there is no dependency of dp[i][j] on it's left or right column, so it doesn't matter in what order we are filling the (i)th row)

  • @aryanpatidar5392
    @aryanpatidar5392 Před 2 lety +18

    before starting this series, dp was like a nightmare for me. I tried a lot of different sources, but there is no match of your content.
    thanks for such overwhelming efforts.

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

    Rather than creating a n*n dp matrix for memoization, one can reduce the space usage by half if he/she creates a triangular matrix. Here's the code:
    vector dp;
    for(int i=0; i

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

      Yeah thats good but even though it would lead to (n*i) T.C which is >> O(n).

  • @Alchemist0P927
    @Alchemist0P927 Před 2 lety +12

    Understood!
    I have gone through a transformation!
    transformation in the way I perceive DP.
    initially, it was the thing I avoided listening to, now I came here and solved these questions by myself first and then watched your explanations.
    Thanks a lot for helping me and many others of my kind.

  • @aditikothari1185
    @aditikothari1185 Před rokem +4

    Just after watching 4-5 videos of this playlist ,I felt so confident in Dynamic programming. Earlier I used to think of dynamic programming as something really difficult and tough to crack , but after watching just 5 videos of this playlist, I started loving this topic. The entire credit goes to this one person , STRIVER.
    Big fan of your teaching style , feeling so happy that I came across this channel.
    May you keep obliging students with your knowledge and teaching skills 🙌

  • @lightninghunterCR
    @lightninghunterCR Před rokem +1

    First time ever that I am going to watch his lecture after coding the question out. First it seemed complicated but then when I used the three tips told by him it just came out of the flow. Started with recursion -> memoized code -> tabulated version and then space optimised it to O(n).
    Might not be so special to all, but this feels so good to reach optimal solution to an unsolved problem of dp. Now I am gonna watch this lecture just to review what I could have done better.

  • @SR-we1vl
    @SR-we1vl Před 2 lety +24

    Note for JAVA folks, if you're trying O(N) space solution and not getting the right answer that is because of this line in front = cur; because in Java, simple assignment of one array to another makes a shallow copy of the assigned array viz. both the arrays get affected if there is any change happened in any one of the array. So the simple solution in java is:
    front = cur.clone(); // creates deep copy of the array in Java

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

      Thank you, I wasn't getting the correct answer because of this. But in the previous problems(minimum path sum) , the array assignment was working fine without clone() method.

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

      You are a genius :) @SR

    • @vaibhavnayak3416
      @vaibhavnayak3416 Před 2 lety

      int[] dp1 = new int[tri.size()];
      for(int i=0;i=0;i--) {
      int[] newDp = new int[dp1.length];
      for(int j=i;j>=0;j--) {
      int down = tri.get(i).get(j) + dp1[j];
      int dia = tri.get(i).get(j) + dp1[j+1];
      newDp[j] = Math.min(down, dia);
      }
      dp1 = newDp;
      }
      return dp1[0];

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

      If you initialize the newDp array within the for loop you do not need to do clone stuff.

    • @saurabhjejurkar5065
      @saurabhjejurkar5065 Před rokem

      Thank You so much bro

  • @wolborg1798
    @wolborg1798 Před rokem +1

    I've been a student of scaler academy, they also explain concepts very nicely but the only difference I've found is they at some point get lost in explaining so much that they go out of structure and sometimes it doesn't feels smooth to run by mind. You sticking to single framework of "1. index 2. do stuffs 3. min/max/optimize" and carrying the same translated version in DP is very comforting to cognate things. Best part is after watching DP lec 7, I solved problems of lec 8,9,10,11 by my own without watching the lecture within an avg time of 10min on each WITHOUT EVEN FORMULATING THE RECURSION FORMULA ON NOTEBOOK. Due to sticking to single framework, it becomes sooooo smooth to formulate the recursion formula within mind itself and I directly wrote down the tabulation code ❤

  • @ishankgera1060
    @ishankgera1060 Před rokem +5

    I just did last 3 questions on my own .... Sky high confidence !! Thanks a lot Striver Guruji

  • @manangandecha8424
    @manangandecha8424 Před 15 dny +1

    "understood"
    Thank You SO Much STRIVER for teaching such an amazing stuff in the most easy way.
    Frankly, I was afraid of DP before starting your DP playlist. But now, I solved this particular problem by myself starting from Recursion to Space Optimization....
    Thank You Again 💚

  • @Faixtel
    @Faixtel Před 2 lety +5

    i was strugling to solve questions when I started the series, now I am able to understand and solve by myself. Thank You soo much brother.

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

    hats off to this legend i am able to code/logic my own ... still saw his video to cross verify ... loved it bro

  • @pritishpattnaik4674
    @pritishpattnaik4674 Před 2 lety +5

    The way you explain the things soo deeply , the concepts are printed in my mind
    Love from Bhubaneswar , Odisha :)

  • @RanjithKumar-ib7pn
    @RanjithKumar-ib7pn Před 2 měsíci

    It is 2024 and you are the best tutor I have ever come across. Kudos to your work sir!!

  • @thatlostsoul
    @thatlostsoul Před 2 lety +14

    First of all, I Appreciate your work man. Thanks for your hard work. There’s a doubt, what if in tabulation we move from (0,0) to (n,0)……(n,m), will it still be considered a bottom up solution?

    • @takeUforward
      @takeUforward  Před 2 lety +19

      Nah! How u move does not matters.
      Recursion-> top down
      Tabulation-> bottom up

    • @arkajyotimukhopadhyay8050
      @arkajyotimukhopadhyay8050 Před 2 lety

      No, you cannot go from 0,0 to n,0 or n,m beacuse you need previous for current to fill that is you need to come from bottom to top in order to calculate the current row !! Hope you understand

    • @anuragprasad6116
      @anuragprasad6116 Před rokem

      for new viewers: 16:45

  • @vinaylj
    @vinaylj Před 2 měsíci

    Striver is really good at teaching DP. my friend suggested me his playlist and I'm really glad I took his suggestion.

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

    Perfect explanation of how dp and space optimization can be done. such a Amazing video man.

  • @riteshbisht94
    @riteshbisht94 Před 7 měsíci +1

    🗿 Space optimization at the end is the thing that makes your dp videos God level 🔥
    Just Stunning 💥

  • @shubhansu-kr
    @shubhansu-kr Před 2 lety +13

    June 2022:
    I solve leetcode daily challenge everyday, June's challenges are focused on DP mostly, so i decided to follow along this series to help me understand DP concepts. I solved today's challenge by myself and came here to continue the series. Surprise surprise It's the same question, ThankYou for such good explanations.

  • @himanshuagrawal8012
    @himanshuagrawal8012 Před 2 lety +10

    I did tabulation in this way, from first row to last row.It was easier that discussed in video.
    #include
    int minimumPathSum(vector& triangle, int n){
    // Write your code here.
    vector dp(n,vector(n,0));

    for(int i=0;i

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

      How is it any easier than what's discussed in the video

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

      @@rahulchaudhary2441 It is because we are thinking of each and every possible case here, and not generalizing

    • @rahulchaudhary2441
      @rahulchaudhary2441 Před 2 lety

      @@himanshuagrawal8012 I think yes, if you choose to directly go for the tabulation method rather than going from intuitive recursive one.

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

    Solution using one DP array only.
    Hey, striver. Really appreciate your efforts.
    Just because of you I feel much more confident in DP now.
    For this question, if we run the loop from 0 to

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

    Isn't the problem statement wrong? (code studio link)
    It is: " if you are at index j in row i, then you can move to i or i + 1 index in row j + 1 in each step."
    Shouldn't it be: " if you are at index j in row i, then you can move to j or j + 1 index in row i + 1 in each step."
    So at next row, either at j, or j+1, right?

  • @user-ed5no7qm8x
    @user-ed5no7qm8x Před 19 dny

    I am able to think myself about the soultion till space optimization before watching your complete video. Thaks a lot. You made dp simple for me

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

    hey, striver, before watching this lecture I solved this using (n-1) to 0 recursion fashion, which has a time complexity O9=(n.2^n) because standing at last row, I need to call all the cells inside a for loop.
    yes, 0 to (n-1) should be preferable here, because before returning either in tabulation or memoization don't need to campare and return the minimum.
    but in my fashion I didn't get TLE in memoization, then how u got TLE in ur memoization because in both fashion T.C will be O(n^2) after applying memoization.
    and thank you very much, you are teaching me a lot :-)

    • @shravani2922
      @shravani2922 Před 2 měsíci

      yes you right we can go from n-1 to 0 as well you wont get TLE

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

    first time i wrote full code myself just after understanding 2-3 min of video, i can't explain how much confident I am in dp. Have to say best dp playlist ever, thank you so much Raj Bhaiaya.

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

    Now space optimisation seems so easy
    Ty❣️

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

      Bro how to calculate time complexity of recursive function

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

      Im not able to think it..

  • @patrioticphoenix3542
    @patrioticphoenix3542 Před 18 dny

    Striver, you are a saviour for us. I was able to do this question by myself. Thanks a lot for providing such a valuable content :)

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

    Understood.
    Please do not reduce the time length. This is perfect. Please do not reduce quality.

  • @shauryasoodeno-0162
    @shauryasoodeno-0162 Před 7 měsíci +1

    i did the space optimization from (0,0) to (m-1,n-1), for me it was easy to understand as in the previous lecture's also you used the same approach
    here the code for that in java(you can ask chatgpt to convert it into c or c++)
    public static int minimumPathSum(int[][] arr, int n) {
    int[] dp=new int[n];
    dp[0]=arr[0][0];
    int min=Integer.MAX_VALUE;
    for(int i=1;i

  • @ankitadas5833
    @ankitadas5833 Před 2 lety +18

    Understood Sir .
    I found that if someone has enough knowledge in Recursion ,it should be easy for them to learn Dynamic Programming. Right Sir?

  • @amartyadas5-yriddmechanica597

    I think instead of two arrays, the space optimization can be done with a single array(dp) itself. Because we are allowed to go down and down-right, when we calculate ans for (i,j), there is no further use of (i+1,j). Hence we can directly put that calculated ans in dp[ j ]. Do let me know if I am wrong.

    • @indraneel6601
      @indraneel6601 Před 2 lety

      Nope that would manipulate the values in down and diagonal
      Lets say :
      2
      3 4
      6 5 7
      4 1 8 3
      if you are changing the values in the same dp array i.e prev[j] then at i = 1 and j = 0 prev[j] or prev[1] would result in 10 due to min(10,13)
      but the result is 9. Try figuring out.

  • @dharsan.s7937
    @dharsan.s7937 Před 2 lety +7

    Bro when iss cp sheet release pls replay bro

  • @AfrinJahanBME
    @AfrinJahanBME Před 2 měsíci

    Amazing playlist for DP, understood each and every concept. Thank you very much💚

  • @prakritisaraf6124
    @prakritisaraf6124 Před rokem

    Thanks would be a very small word of appreciation for the incredible work you do .
    After watching dp vieos for 2 days, I could do the recursive approach to memoization and tabulation all , without watching your solution,THANK YOU!!

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

    thank you , getting problems very well
    did submit it before watching video and then watching video for better concepts and methods
    like i didn't got the how to write the recursion for particular problem so i tried for DP and i did it and it made my day
    thank you again

  • @crosiaPinter
    @crosiaPinter Před rokem

    Solved without watching this video. It was all thanks to your top class previous videos. Hats off to your teaching skills. Thank you so much.

  • @borntolearn661
    @borntolearn661 Před 2 lety

    I think it's the first time in my life that I am visiting an edu based channel on youtube everyday and reloading the uploads to find whether striver uploaded or scheduled a new video..."ANYONE CAN OPEN A CZcams CHANNEL AND TEACH , BUT ONLY A VERY FEW CAN CREATE AN IMPACT"..

  • @bablushaw6856
    @bablushaw6856 Před rokem +2

    Is it really me Solving dynamic problems with clear understanding and confidence or am I dreaming? Thanks Striver.

  • @akshayaashok8794
    @akshayaashok8794 Před 5 měsíci +1

    Understood Striverrr!!!! Especially the tabulation part was very insightful!

  • @prabhpreetsingh8665
    @prabhpreetsingh8665 Před 2 měsíci

    bhaiya maine last ke 3 question khud se solve kr liyea bina solution deakhe
    yn yoh ab mai intelligent hogya hu(mushkil h) yn fir aapne padhaya bht acha hai
    jo b hai maza aarha hai😃

  • @sayakghosh5104
    @sayakghosh5104 Před rokem +1

    Absolute Gem!!! COuld do it easily, without seeing your video, thanks for the concept build up.

  • @anujrathore5726
    @anujrathore5726 Před 2 měsíci +1

    i did this que by myself , thanks striver

  • @skilz9525
    @skilz9525 Před rokem

    2 mins into the video and I was able to solve this in 5 mins. Thanks to striver's unmatchable teaching technique

  • @AbhishekKumar-cv1dh
    @AbhishekKumar-cv1dh Před 10 měsíci

    I am finally able to do recursion + memoization + tabulation with space optimization all by myself, thankyou so much for your teachings Striver ❤‍🔥❤‍🔥❤‍🔥❤‍🔥

  • @HarshitMaurya
    @HarshitMaurya Před 2 lety

    i'm wondring that is it really me ? who was not able to approach any dp question until I started your dp series , and now I'm able to solve every problem before watching the solution video for that , Thanks man

  • @abdalla4425
    @abdalla4425 Před 8 měsíci

    Solved it myself without the video! I understand what I am looking at for this problem due to the previous problems having such a good explanations.

  • @AryanVani-ml2ec
    @AryanVani-ml2ec Před 11 měsíci

    Thanks Striver, was able to make it after watching just your 11 videos.
    class Solution {
    public int f(List triangle,int row,int idx,int [][] dp)
    {
    if(dp [row][idx] != -1)
    {
    return dp[row][idx];
    }
    if(row == triangle.size()-2)
    {
    return dp[row][idx] = Math.min(triangle.get(row).get(idx)+triangle.get(row+1).get(idx),triangle.get(row).get(idx)+triangle.get(row+1).get(idx+1));
    }
    int down = triangle.get(row).get(idx) + f(triangle,row+1,idx,dp);
    int dia = triangle.get(row).get(idx) + f(triangle,row+1,idx+1,dp);
    return dp[row][idx] = Math.min(down,dia);
    }
    public int minimumTotal(List triangle) {
    if(triangle.size() == 1)
    {
    return triangle.get(0).get(0);
    }
    int [][] dp = new int [triangle.size()][triangle.size()];
    for(int [] i : dp)
    {
    Arrays.fill(i,-1);
    }
    return f(triangle,0,0,dp);
    }
    }

  • @meenakumar8733
    @meenakumar8733 Před měsícem

    Man o Man....Understanding dp is no longer myth

  • @nitishbharat9942
    @nitishbharat9942 Před rokem +2

    when u don't need to see code after explanation of logic then u can assume watching one and only striver bhaiya k playlist 🥰🥰❤❤

  • @dhyanprasad5611
    @dhyanprasad5611 Před rokem +1

    yooooo i tried this on my own after listening to the logic and got all testcases passed... #STRIVEROP #STRIVERNATION

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

    Best DP series on youtube bhaiya....
    Very helpful.

  • @user-el6hv6em7m
    @user-el6hv6em7m Před měsícem

    Understood ! thanks for this amazing series...

  • @_HRhackjack
    @_HRhackjack Před 2 lety

    Understood and fantasized with the beauty of problem Solving

  • @sanimarmanghera5027
    @sanimarmanghera5027 Před 3 měsíci +1

    understood sir! HATS OFF!

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

    hats off to you!! lovely explanantion! no words🙏

  • @shivamshrey47
    @shivamshrey47 Před rokem

    Without using a 'cur' reference. Space complexity: O(n) instead of O(2n).
    def minimumPathSum(triangle, n):
    # base case: last row
    dp = triangle[-1]
    for i in range(n - 2, -1, -1):
    for j in range(i + 1):
    dp[j] = triangle[i][j] + min(dp[j], dp[j + 1])
    return dp[0]

  • @MukeshKumar-cc3uh
    @MukeshKumar-cc3uh Před 7 měsíci

    Huge amount of respect. Thank you Striver. "Understood".❤

  • @DevashishJose
    @DevashishJose Před 9 měsíci

    understood completely, thank yo so much, I am genuinely excited while solving these problems now. Thank you

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

    In case if anyone wants to start from bottom can use below code. You will get correct answers for small cases but TLE for large case as Complexity is O(N^3). So it is better to start from i=0 as solved by Striver Sir.
    int go(int i,int j,vector &arr,vector &dp){
    if(i==0 && j==0){
    return arr[i][j];
    }
    if(i

    • @user-zz4pi1bw7j
      @user-zz4pi1bw7j Před 7 měsíci

      #include
      int f(int i,int j,vector& t,vector& dp){
      if(i==0 && j==0){
      return t[i][j];
      }
      if(ii || j

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

    Understood sir 😁, i know there will be lots of aferts you are putting on each lecture of dp but i am waiting every day when new lecture will come, my telling me some time why not you upload all videos at a time😂 but it is not possible very well explanation sir👍

    • @takeUforward
      @takeUforward  Před 2 lety +6

      Yes every lecture takes a lot of time, you can see by the number of codes written.

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

    great striver is being the one and only one

  • @adityajoshi3922
    @adityajoshi3922 Před 2 lety

    love the space optimization part it's so analytical

  • @6mahine_mein_google
    @6mahine_mein_google Před 2 měsíci

    In the second loop we can do it by starting from j=0 to j

  • @hashcodez757
    @hashcodez757 Před měsícem

    "UNDERSTOOD BHAIYA!!"

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

    one correction to the solution given in the video
    initializing dp array to -1 may not work in every single case as given triangle can have negative elements also
    so having -1 @ any cell of dp does not mean that the solution is not computed already
    Hope it makes sense to you

    • @abhishekcs5468
      @abhishekcs5468 Před 2 lety

      I used INT_MAX, but atleast the algorithm works correctly with -1 as well.

  • @AbhishekShukla-zr1hq
    @AbhishekShukla-zr1hq Před 2 lety

    bro this is perfectly understand from point to point

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

    can be done in constant space too :
    int minimumTotal(vector& triangle) {
    int n = triangle.size();
    for(int i=1; i

  • @sukhpreetsingh5200
    @sukhpreetsingh5200 Před rokem +1

    Understood and I am able to solve this question myself

  • @nilimsankarbora5911
    @nilimsankarbora5911 Před 8 měsíci

    loved this amazing Technique of solving DP on Grids 💌💌

  • @shhhhhhhhhh2686
    @shhhhhhhhhh2686 Před 2 měsíci +1

    understood,
    thankyou!

  • @tanmaymahajan8059
    @tanmaymahajan8059 Před rokem

    Thankyou striver sir
    This first dp problem which I solved for recursion to space optimization all my self

  • @JothiprakashThangaraj
    @JothiprakashThangaraj Před měsícem +1

    understood.. thanks

  • @harshvardhansingh2272

    Man awesome content
    did it by myself
    and yeah i did it by using nested loop for col from 0 to i instead of i to 0 like u did and it works
    so thanks again

  • @rupa1772
    @rupa1772 Před 2 lety

    Never seen such space optimization in any videos wow amazing 😯

  • @cinime
    @cinime Před 2 lety

    Understood!! I really, really, really appreciate for your explanation!!!

  • @miheersalunke4045
    @miheersalunke4045 Před 2 lety

    US. Thanks a lot! You are too good in teaching such tough topics.

  • @rahulchaudhary2441
    @rahulchaudhary2441 Před 2 lety

    Awesome content, a whole hearted "understood" from my side.

  • @animeking8205
    @animeking8205 Před 5 dny +1

    Understood sir ❤❤❤

  • @2amCoder
    @2amCoder Před 6 měsíci +1

    this can be also done with single array as we dont need front one every time we will oveeride the value every time

  • @visheshagrawal8676
    @visheshagrawal8676 Před rokem

    thanks bro for developing thinking solved this question by myself

  • @warriorgaming9509
    @warriorgaming9509 Před rokem

    How the heck u make Space Optim so Smooth man................Hatsss Offff 🤩🤩

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

    we can reduce space and time complexity by this :
    int minimumTotal(vector& triangle) {
    int m = triangle.size();
    vector dp = triangle[m-1];
    for(int i = m-2; i>=0 ;i--)
    {
    for(int j = 0; j

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

    Here in recursive and tabulation method the time complxity is O(n^2) in both only space complexity is less in tabulation method.As time complexity is same for both method why we are not getting TLE for tabulation method??

    • @dhruv_jain99
      @dhruv_jain99 Před 2 lety

      31:12
      in recursion solution at line 6 there is wrong condition.
      dp[i][j] != -1
      is wrong condition as we have range
      -10^6

  • @thisismr900
    @thisismr900 Před rokem

    @22:05
    it should be i-1 and j-1 resp as tabualtion is opposite of the rec approach
    sorry
    i get it
    Im wrong
    we are already traversing in opposite direction
    so whatever is there in video , is bloddy 100% correct man
    US!

  • @Balasubramaniam.M
    @Balasubramaniam.M Před 2 měsíci

    Understood very very welllllll..

  • @LowkeyCoder
    @LowkeyCoder Před 9 měsíci

    "Understood " thank you raj bhaiya !

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

    Understood Striver...
    And by seeing this video I too optimized space
    rather than cur and front, we can use triangle and see this is working fine
    Hope you like it
    int minimumPathSum(vector& triangle, int n){
    for(int i = n-2;i>=0;i--){
    for(int j = i;j>=0;j--){
    int d = triangle[i][j] + triangle[i+1][j];
    int dg = triangle[i][j] + triangle[i+1][j+1];

    int cur = min(d,dg);
    triangle[i][j] = cur;
    }
    }
    return triangle[0][0];
    }

  • @sannareddymonesh7598
    @sannareddymonesh7598 Před rokem

    This question was asked in D.E Shaw in OA

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

    UNDERSTOOD... !
    Thanks striver for the video... :)

  • @ganeshkamath89
    @ganeshkamath89 Před 2 lety

    Thanks Striver. Understood Triangle problem.

  • @shuaibjawed1798
    @shuaibjawed1798 Před měsícem

    Bottom up revusive sol- class Solution:
    def minimumTotal(self, triangle: List[List[int]]) -> int:

    n = len(triangle)
    # for i in range(n):
    # for j in range(0,i+1):


    def calc(x,y):
    if x == 0 and y ==0:
    return triangle[0][0]

    if x < 0 or y < 0 or y > x:
    return float('inf')

    up = calc(x-1,y)
    up_left = calc(x-1,y-1)
    return triangle[x][y] + min(up,up_left)

    min_path = float('inf')
    for i in range(n):
    min_path = min(min_path,calc(n-1,i))

    return min_path

  • @dharmeshpoladiya9047
    @dharmeshpoladiya9047 Před 2 lety

    Understood 💯💯 Great Explanation. Thank you very much for all you efforts🔥🔥

  • @keshavprasad1017
    @keshavprasad1017 Před rokem

    By far the best dp series 👌👌👌 Thank You soooo much ...